C#匿名函数和Lambda表达式

 class Program
    {
        delegate void MyDelegate(string str);
        static void Main(string[] args)
        {
            //正常调用
            MyDelegate myDelegate = new MyDelegate(CW);
            myDelegate("正常调用");

            //匿名函数
            MyDelegate myDelegate2 = delegate (string str) { Console.WriteLine(str); };
            myDelegate("匿名函数");

            //Lambda表达式
            MyDelegate myDelegate3 = (string str) => { Console.WriteLine(str); };
            myDelegate3("Lambda表达式");

            Console.ReadKey();
        }

        static void CW(string str)
        {
            Console.WriteLine(str);
        }
    }
原文地址:https://www.cnblogs.com/xiaobao2017/p/12204320.html