匿名方法与委托关联调用实例

             1:使用委托的方法:

         delegate int MyDelegate(int i);

        static void Main(string[] args)

        {

            MyDelegate mydel = new MyDelegate(a);

            int b=mydel(1);

            Console.WriteLine(b);

            Console.ReadKey();

        }



        public static int a(int i)

        {

            Console.WriteLine("Hello kiddle" + i.ToString());

            return i + 2;

        }

           2:使用匿名方法:

        delegate int MyDelegate(int i);

        static void Main(string[] args)

        {

            MyDelegate mydel = new MyDelegate(a);

            int b=mydel(1);

            Console.WriteLine(b);

            Console.ReadKey();

        }



        public static int a(int i)

        {

            Console.WriteLine("Hello kiddle" + i.ToString());

            return i + 2;

        }

原文地址:https://www.cnblogs.com/wangyhua/p/4050625.html