class Test { delegate K proxy<T, K>(T t, K k); //泛型委托,注意返回值的写法,返回值的类型K先于其声明proxy<T,K>中的K,这是C#底层的事 public static void Main() { proxy<int, string> pxy = varCat; proxy<int, int> padd = addTest; string s = pxy(10, "xyz"); int sadd = padd(13, 12); var obj = new { ID = 10, age = 30, name = "tom" }; //匿名类,变量都是只读的 proxy<int, int> paddEnonymous = delegate (int x, int y) //匿名函数 { return x + y; }; proxy<int, int> paddLambda = (int x, int y) =>//lambda表达式,相当于一种匿名函数 { return x + y; }; } public static string varCat(int i, string s) { return i + ": " + s; } public static int addTest(int x, int y) { return x + y; }
时间: 2024-10-11 07:36:36