C
C#2w ago
LastExceed

do lambda params support any form of deconstruction syntax?

i would have expected one of these to work:
new[] { (1, 2) }
.Select((a, b) => a + b);

new[] { new { a = 1, b = 2 } }
.Select((a, b) => a + b);
new[] { (1, 2) }
.Select((a, b) => a + b);

new[] { new { a = 1, b = 2 } }
.Select((a, b) => a + b);
but unfortunately they dont. is anything like this possible in lambda params at all?
3 Replies
Angius
Angius2w ago
It's an, as of yet, unanswered proposal: https://github.com/dotnet/csharplang/discussions/258
GitHub
Proposal: Tuple deconstruction in lambda argument list · dotnet csh...
A lambda that accepts a (single) tuple as argument can only be defined with the tuple as a single argument and not by the tuples items. I’d like to see that the tuple deconstruction also works in t...
Angius
Angius2w ago
There's someone who said they'd champion it, but there's no ETA or anything yet
Anton
Anton2w ago
No but this should be fine
[(a: 1, b: 2)].Select(x => x.a + x.b)
[(a: 1, b: 2)].Select(x => x.a + x.b)
Want results from more Discord servers?
Add your server