I am just thinking how to convert this:
List.Where(X=>X>5);
to non-lambda expression code.
I cannot figure out how to get Func working here.
There are two reasonably simple possibilities for creating delegates without using lambda expressions:
Write a method and use a method group conversion
private static bool GreaterThan5(int x)
{
return x > 5;
}
...
var query = list.Where(GreaterThan5);
Use an anonymous method
var query = list.Where(delegate(int x) { return x > 5; });
Neither of those are as clear as using a lambda expression though. For more complicated examples where you actually want to capture local variables, the "write a separate method" version would get a lot more complicated.
While I don't understand the purpose of this, you can do it like this:
bool MyFilterFunction(int x)
{
return x > 5;
}
Then rewrite your code:
List.Where(MyFilterFunction);
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