1. anonymous method to start the conversion to a single expression Lambda expressions do not require brackets allow the compiler to infer the type parameter to remove unnecessary brackets
2.Lambda expression is a simplified function can be used to create an anonymous delegate or expression tree Lambda expressions can be passed as an argument
3. It acts on the value returned by a function call to the function call to use
3.Lambda can create a delegate instance simplify the code
class Program { the delegate int weituo ( int X, int Y); static void the Main ( String [] args) { // delegate function and Lambda weituo weituo = (A, B) => A * B; int J = weituo ( . 3 , 2 ); Console.WriteLine (J); } }
Entrusted to achieve the above code number is multiplied by two and Lambda go to define two parameters of a delegate instantiation then delegate the front and rear Lambda expressions commissioned two determination values are multiplied
Finally, a value of a variable j to receive the last delegate inside two output parameters
class Program { static void the Main ( String [] args) { // anonymous function and Lambda Func < int , int , int > = Action (texttaxt, AA) => texttaxt * AA; int J = Action ( . 3 , . 5 ); Console.WriteLine (J); Console.Read (); } }
The above code is realized and Lambda anonymous function of the function Func go to define a parameter which is a function that returns a value inside the pre-write type Int last two parameters representative of the input parameter representative of the output
Then to achieve the same function assignment and Lambda output
public class sumClass { public static T sum<T>(T x,T y)where T:struct { dynamic v1 = x; dynamic v2 = y; return (T)(v1 + v2); } }
Go above code is defined a class sumClass then write a generic method parameter constrained to pass a method of adding T represents a generic method which is
class Program { static void Main(string[] args) { int a = 3; int b = 4; sumClass sumClass = new sumClass(); Console.WriteLine(sumClass.sum(a,b)); Console.Read(); } }
The method is then used to write two constants sumClass then passed over two constants receiving writing method implemented inside the last two numbers together