C# Lambda的几种写法

namespace DelegateConsole
{
    class Program
    {
        public delegate void myVoidDel();
        public delegate string myFuncDel();
        public Func myFunc;
        public Action myAct;

        static void Main(string[] args)
        {
            //old writting 
            myVoidDel myVoidDel = new myVoidDel(delVoid);

            //lambda
            myVoidDel += new myVoidDel(() => Console.WriteLine("This is Void, version 3"));

            myFuncDel myFuncDel = () => "This is function";

            Console.ReadKey();
        }

        static void delVoid()
        {
            Console.WriteLine("This is Void, version 1");
        }
    }
}

你可能感兴趣的:(C#,Lambda)