委托是一种数据类型,可以把方法通过参数传递到另一个方法中,关键字delegate。

可以声明与类相同级别,或与属性相同级别,可以有返回值没返回值,有参数,没参数 。声明例子:

    /// <summary>
    /// 委托:是一个类,继承自System.MulticastDelegate,里面内置了几个方法
    /// </summary>
    public delegate void NoReturnNoParaOutClass();
    public class MyDelegate
    {
        public delegate void NoReturnNoPara<T>(T t);
        public delegate void NoReturnNoPara();
        public delegate void NoReturnWithPara(int x, int y);//1 声明委托
        public delegate int WithReturnNoPara();
        public delegate string WithReturnWithPara(out int x, ref int y);
    }
View Code

相关文章:

  • 2022-12-23
  • 2022-03-06
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-08-30
  • 2021-08-21
猜你喜欢
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2021-12-02
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案