A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.
A litle bit of background:
In .Net 1.1 we had delegates.
In .Net 2.0 we had anonymous delegates
In .Net 3.5 we have lambda!!! (this is one of the best things that happens in .Net 3.5)
small sample:
List
int x = 5;
list.Find(NormalDelegate); //Notmal delegate
{
// can't use anything but members and parameters (number)
return number%2 == 0;
}
list.Find(delegate(int num) //anonymous delegate
{
// can use x - or any thing in the block above plus parameters
return num%2 == 0;
});
list.Find(num => num%2 == 0);
Lambda:
Well lambda is just a shorter why to write
The same code above can be write in lambda easly and very shortly
list.Find(n => n % 2 ==9); //Thats it! one short line
if you want to create something longer it will start to look like anonymous delegate
For example
list.Find(n=> {
n = n + x;
return n % 2 == 0;
});
now we need the return "word" (Not like before)
I hope it explain you abit about lambda
You can read more about Lambda Expressions in the msdn
Enjoy (e=> e == Int32.MaxValue); // :)