参考自https://www.cnblogs.com/chenwolong/p/5666196.html
委托:
实质为引用方法的对象,所以参数需要与所引用方法的参数一致;
//委托类型
delegate int calculator(int x, int y);
//创建委托对象
calculator Add = calculator(Adding);
//使用该委托对象
Console.WriteLine("{0}",Add(1,2)); //输出3
//委托引用方法
public static int Adding(int x,int y) return x + y;
匿名方法:
与委托结合使用;
//委托类型
delegate int calculator(int x, int y);
//创建匿名方法
calculator Adding =delegate( int x, int y)
{
return x+y;
}
//使用
Console.WriteLine("{0}",Adding(1,2));//输出3
Lambda表达式
(参数)=>具体方法块, ( x , y ) => x + y 等效于 fun(x,y) return x+y ;
//委托类型
delegate int calculator(int x, int y);
//Lambda表达式
calculator Add = (x, y) => x + y;
//使用
Console.WriteLine("{0}", Add(1, 2));//输出3