委托 匿名 lambda表达式
2019-03-13 11:27 .net小跟班(杜) 阅读(154) 评论(0) 编辑 收藏 举报#region 委托 delegate int ACT(int a, int b); static void Main(string[] args) { ACT act = new ACT(add); int i = add(5, 8); Console.WriteLine(i); Console.ReadKey(); } public static int add(int a, int b) { return a + b; } #endregion #region 匿名 delegate int ACT(int a, int b); static void Main() { ACT act = delegate (int num1, int num2) { return num1 + num2; }; int he = act(4, 8); Console.WriteLine(he); Console.ReadKey(); } #endregion #region Lambda表达式 delegate int ACT(int a, int b); static void Main() { ACT act = (a, b) => a + b; int he = act(4, 8); Console.WriteLine(he); Console.ReadKey(); } #endregion