一:什么叫委托

通过反射发现,委托其实是一个类,继承自System.MulticastDelegate,但是System.MulticastDelegate这个类是特殊类,不能被继承

 

二:委托的声明 

 public delegate void NoReturnNoParaOutClass();
 public class MyDelete
 {
      public delegate void NoReturnNoPara<T>(T t);
      public delegate void NoReturnNoPara();
      public delegate void NoReturnWithPara(int x, int y);
      public delegate int WithReturnNoPara();
      public delegate string WithReturnWithPara(out int x, ref int y);
    }

委托可以声明在类外面,可以声明再类里面

 

三:委托的实例和调用 

      private int GetSomething()
        {
            return 1;
        }
        private int GetSomething2()
        {
            return 2;
        }

        private int GetSomething3()
        {
            return 3;
        }
        private void DoNothing()
        {
            Console.WriteLine("This is DoNothing");
        }
        private static void DoNothingStatic()
        {
            Console.WriteLine("This is DoNothingStatic");
        }
        public string ParaReturn(out int x, ref int y)
        {
            throw new Exception();
        }
View Code

相关文章:

  • 2022-03-11
  • 2022-12-23
  • 2021-05-29
  • 2021-06-17
  • 2021-12-05
  • 2021-08-26
猜你喜欢
  • 2021-09-04
  • 2022-12-23
  • 2021-07-13
  • 2021-10-27
  • 2021-08-01
  • 2021-11-10
相关资源
相似解决方案