when using the "from.. select" form I can assign local variables in Linq with the let
statement. How to capture variables with lambdas? Non working example of what I need:
var result = list.Select(a =>
let localVariable = a.number + 2 // <- obviously non working
new {
Variable = localVariable
}
);
This should work:
var result = list.Select(a =>
{
var localVariable = a.number + 2;
return new
{
Variable = localVariable
};
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With