C# language feature:
applies to
benefit
how to use
=>
, and you put the expression or statement block on the other side.note
example:
delegate int delegate_accept_and_return_int(int i);
delegate bool delegate_accept_int_return_bool(int i);
void Use_of_Lambda_Expression()
{
delegate_accept_and_return_int getsquare = x => x * x; // define delegate using lambda expression
int y = getsquare(5); //y = 25
int testvalue = 5;
// Note delegate definition has access to outer variable testvalue.
delegate_accept_int_return_bool isgreaterthan = (x) => { return x > testvalue; }; // define delegate using lambda expression
bool result = isgreaterthan(6); // result is true
}