很久之前转载的,http://blog.csdn.net/Joyhen/article/details/9699739
今天一个函授式写法的多层嵌套Func搞的头晕,索性回忆下。零碎的代码如下:
public delegate int MyDelegate(int a, int b);
public static int function(int a, int b) { return a + b; }
static void Main(string[] args) {
MyDelegate delfun = new MyDelegate(function);
MyDelegate delkk = delegate(int a, int b) { return a + b; }; //a,b参数不能推断
MyDelegate lambdakk = (a, b) = >a + b; //a,b参数可以根据MyDelegate来推断
Func < int,int,int > funkk = (a, b) = >a + b; //a,b参数可以根据Func的参数来推断
int result = delfun.Invoke(1, 2); //delfun(1, 2);
Console.WriteLine(result);
Console.WriteLine(lambdakk(1, 2));
Console.WriteLine(lambdakk(1, 2));
Console.WriteLine(funkk(1, 2));
Func <