委托

 class Program
  {
         //声明委托
        delegate int MyDelegate(int x, int y);
 
        static void Main(string[] args)
        {
           MyDelegate _myDelegate = new MyDelegate(fun1);
           _myDelegate += fun2;
            Console.WriteLine(_myDelegate(10,23));

           Console.ReadKey();//输出10,返回最后一个注册函数的返回值
       }

       static int fun1(int x, int y)
       {
            return x + y;
        }

        static int fun2(int x, int y)
        {
            return x;
         }      
    }

 

posted @ 2018-09-29 09:58  api-80  阅读(196)  评论(0编辑  收藏  举报