Say you have the following code:
string encoded="9,8,5,4,9";
var nums=from string s in encoded.Split(',')
select int.Parse(s);
It's easy, but what if I want to apply a lambda expression to s in select, but still save it as a declarative query expression, in other words:
string encoded="9,8,5,4,9";
var nums=from string s in encoded.Split(',')
select (s => {});
This, of course, does not compile. But, how can I get lambda there without switching it to free syntax.
Update : thanks to the StriplingWarrior tutorial, I have a confusing but compiled solution:
var result=from string s in test.Split(',')
select ((Func<int>)
(() => {string u="1"+s+"2"; return int.Parse(u);}))();
Func<string,int>, select (s). - - (.. Func, , , - , )?
. . , .
2: , , , ( ?) :
public static class Lambda
{
public static U Wrap<U>(Func<U> f)
{
return f();
}
}
...
var res=from string s in test.Split(',')
select Lambda.Wrap(() => {string u="1"+s+"2"; return int.Parse(u);});
, . - Lambda.Wrap, - .NET 4.0, ? , : Wrap .NET 4.0.