A LAMBDA expression is an anonymous function that can contain expressions and statements, and can be used to create a delegate or an expression tree type. All lambda expressions use the lambda operator =>, and the operator reads "goes to". The left side of the LAMBDA operator is the input parameter (if any), and the right side contains an expression or a block of statements. The LAMBDA expression x + x * x is read as "x goes to X times X". You can assign this expression to a delegate type.
The lambda expression on the right of an expression is called a lambda expression. Lambda expressions are widely used when constructing an expression tree. A LAMBDA expression returns the result of an expression and takes the following basic form:
(input parameters) = Expression
A lambda statement is similar to a lambda expression, except that the statement is enclosed in curly braces:
(input parameters) = {statement;}
the-= = operator hasthe same precedence as the assignment operator (=) and is the right associative operator.
Lambda is used in method-based LINQ queries as a where and where (IQueryable, String, array<object>[]()[]) Parameters such as standard query operator methods.
Lambda is not allowed on the left side of the IS or as operator.
All restrictions that apply to anonymous methods also apply to LAMBDA expressions.
delegate void Del (int x, int y);
Del d = (m, n) = = {int r = m + N; Response.Write (R); };
D (6, 4);
Result:10
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
int oddnumbers = numbers. Count (n = = n% 2 = = 1);
Result:5
var lessThan6 = numbers. TakeWhile (n = n < 6);
Response.Write (Lessthan6.count ());
Result:4
delegate int del (int i);
Del mydelegate = x + x * x;
Response.Write (MyDelegate (5);
Result:25 Original: http://blog.itpub.net/12639172/viewspace-464474/
C#3.0 's magical lambda expressions and lambda statements