1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| namespace XLZF_Lambda { public class My_lambda { public delegate void Noreturn_void(); public delegate string Noreturn_string(); public delegate void Noreturn(string name); public delegate int Noreturn_Int(int x, int y);
public static void Show() { Console.WriteLine("委托咯~~~~");
#region 委托+lambda 表达式演化过程
Noreturn method = new Noreturn(Study);
method.Invoke("张三");
Noreturn method1 = new Noreturn( delegate (string name) { Console.WriteLine("{0}学习不停止", name); });
method1.Invoke("张三");
Noreturn method2 = new Noreturn( (string name) => { Console.WriteLine("{0}学习不停止", name); });
method2.Invoke("张三");
Noreturn method3 = new Noreturn( (name) => { Console.WriteLine("{0}学习不停止", name); });
method3.Invoke("张三");
Noreturn method4 = (name) => { Console.WriteLine("{0}学习不停止", name); };
method4.Invoke("张三");
Noreturn method5 = (name) => Console.WriteLine("{0}学习不停止", name);
method5.Invoke("张三");
Noreturn method10 = (name) => Console.WriteLine("{0}学习不停止", name);
method10.Invoke("张三");
#endregion
#region 委托+lambda表达式练习
Noreturn_Int noreturn_Int = (x, y) => { return x + y; };
noreturn_Int.Invoke(1, 2);
Noreturn_Int noreturn_Int1 = (x, y) => x + y;
noreturn_Int1.Invoke(11, 22);
Noreturn_void noreturn_Void = () => { };
noreturn_Void.Invoke();
Noreturn_string noreturn_String = () => "1";
noreturn_String.Invoke();
#endregion
#region 泛型委托,有这个泛型委托,也就是不用再特意的去声明一个委托了
Action act1 = () => { };
Action<string> act2 = s => { }; Action<int, string, Double, decimal, float, Action> act3 = (a, s, d, f, g, h) => { };
Func<string> fun = () => "123";
Func<string, int, Double, Func<decimal>, Action, decimal> fun1 = (a, s, d, f, g) => Convert.ToDecimal(12.22);
#endregion }
public static void LinqShow() { List<int> intlist = new List<int>();
for (int i = 0; i < 100; i++) { intlist.Add(i); }
foreach (int item in intlist.Where<int>(num => num > 55)) { Console.WriteLine(item); } }
public static void Study(string name) { Console.WriteLine("{0}学习不停止", name); } } }
|