Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 242
Random Avatar asked Nov 30 '16 22:11

Random


People also ask

Does hep C go away?

It is highly curable ... Direct-acting antiviral medications — given over a 12-week period — actually can cure early acute hepatitis C better than 90% of the time.

What is || in C programming?

Logical OR operator: || The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise. The operands are implicitly converted to type bool before evaluation, and the result is of type bool .

What does hep C pain feel like?

Many chronic HCV sufferers also complain of getting aches and pains. Large numbers get sharp pains over the liver (found in the upper right corner of the abdomen) which can sometimes be very alarming. These pains are not necessarily connected with severe liver disease.


2 Answers

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

like image 168
Patrick McDonald Avatar answered Sep 21 '22 14:09

Patrick McDonald


Deconstruction in Linq queries isn't supported in C# 7.0.

Only three forms of deconstruction made it into C# 7.0 (deconstruction in assignment, in "foreach" loop and in "for" loop). But when the language design committee considered all the possible places that declare variables (and thus would be candidates for deconstruction) and prioritized them, the deconstruction in "let" (and possibly "from") clauses were next in line.

Please make sure to leave a note or a thumbs up on https://github.com/dotnet/csharplang/issues/189 if you feel this would be useful.

like image 44
Julien Couvreur Avatar answered Sep 22 '22 14:09

Julien Couvreur