C#匿名方法

首先,介绍匿名方法的发展史,以代码展示:

static void Main(string[] args)
        {
            //最原始的委托
            TestDelegate testDelA = new TestDelegate(Method);

            //C# 2.0 后 Anonymous Method
            TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); };

            //C# 3.0 lambda
            TestDelegate testDelC = (s) => { Console.WriteLine(s); };

            testDelA("Hello, this is a delegate!");
            testDelB("This is a anonymous Method!");
            testDelC("This is a lambda Method");
            Console.ReadLine();
        }

        static void Method(string s)
        {
            Console.WriteLine(s);
        }
身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
原文地址:https://www.cnblogs.com/birdofparadise/p/7078885.html