1. Anonymous Methods
is essentially a method where any delegate can be assigned using an anonymous method
1 Example: 2 // Anonymous methods also use the delegate keyword 3 func<int ,int ,intdelegate (int _x,int _y) 4 {5 return _x + _y; 6 };
2.Lambda-expression
can be used as an anonymous method instead
Example:
1 //Anonymous Methods2func<int,int,int> =Delegate(int_x,int_y)3 {4 return_x +_y;5 };6 //lambda expression, no keyword7func<int,int,int> = (_x, _y)8 {9 return_x +_y;Ten};
PS: As long as the delegate can be anonymous, as long as it is anonymous can be used lambda expression
PS: When the function parameter has only one time, can not add parentheses:func<int,int> a = B=>{return B};
when the statement of a function body has only one sentence, it can not be enlarged by parentheses, or it may not be called return:func<int,int> a = b=>b;
C # Programming Note (anonymous method, lambda expression)