Search code examples
c#linqtuplesc#-7.0

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 = Convert(word)
             select result.Original

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


Solution

  • It seems not.

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

    Edit

    Issue moved to dotnet/csharplang#355