Foundation, you are master, please float away ...
Usually do the project write code rarely use lambda expression, hereby add, record down.
1 What is a lambda expression?
MSDN statement: using a lambda expression, you can write a local function that can be passed as a parameter or returned as a function call value
At first glance, really a bit uncomfortable, Chinese did not learn!!! It's machine-translated, and it's a roar ...
Take an example.
Lambda expression x=>x*x input x, output x*x
If you have one of these methods:
1 public int getX2 (int x) {return x*x;}
Note that there is a difference, how can the expression be the same as the method?
c# method is passed as a parameter! Yes, that's the Commission. For example:
1 Delegate int del (int i); 2 Static void Main (string[] args)3{4 del mydelegate = x = x * x;< /c15>5 int j = mydelegate (5//j =6 }
2 Lambda type
An expression lambda
The lambda expression that the expression is on the right side of the = = operator is called expression Lambda. The expression lambda returns the result of an expression and takes the following basic form:
(input parameters) = Expression
See Example:
Static void Main (string[] args) { int56; Func<intint int > f = ((x1, y1) = x1 + y1); Console.WriteLine (f (x, y). ToString ()); Console.read (); }
What's the result? 11
Func is a generic delegate that typically comes with a return value.
Statement Lambda
A statement lambda is similar to an expression lambda expression, except that the statement is enclosed in curly braces:
1 (input parameters) = {statement;}
Such as:
1 Static void Main (string[] args)2 {3 action<string> F = (x) = = {Console.WriteLine (x);}; 4 F ("hello,world"); 5 console.read (); 6 }
Where: Action is a non-return value, generic delegate that is provided internally by. Net.
The structure is as follows:
1 delegate void Action (); 2 delegate void Action<in t> (T obj); 3 delegate void Action<in t, (T obj,t1 obj1); 4 delegate void Action<in t,in t2> (T obj,t1 obj1,t2 obj2);
...
Just write it down here.
C#lambda expression Recording