public static void Main(string[] args) { //匿名方法 //可以用delegate来代替方法名 TextDelegate01 method01 = delegate() { Console.WriteLine("HelloWorld"); }; method01(); TextDelegate02 method02 = delegate(int x, int y) { return(x + y); }; int result = method02(5, 4); }
public static void Main(string[] args) { //Lambda表达式 //=>Lambda运算符,读作gose to TextDelegate01 method01 = () => { }; TextDelegate02 method02 = (int x, int y) => { return(x + y); }; //简化01 method02 = (int x, int y) => x + y; //简化02 method02 = (x, y) => x + y; }