Random Random - 1 year ago 64
C# Question

Does C# 7 allow to deconstruct tuples in linq expressions

I'm trying to deconstruct a tuple inside a Linq expression

// somewhere inside another method
var result = from word in words
let (original, translation) = Convert(word)
select original

Here is a signature of the method returning a tuple

(string Original, string Translation) Convert(DictionaryWord word)
// implementation

But it's not a valid syntax. I can only access tuple values without deconstruction:

var result = from word in words
let result = GetWord(word, mode)
select result.Original

Is there a proper way to deconstruct it or it's not supported inside Linq expressions?

Answer Source

It seems not.

There's an open issue for this on GitHub: https://github.com/dotnet/roslyn/issues/6877

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download