namespace classanddelegate
{
    class Program
    {
        static void Main(string[] args)
        {
            //这是类的实例化
            Test test = new Test();
            //创建一个委托实例的时候,需要确定需要与哪些方法关联起来。
            MyDelegate d = new MyDelegate(MyMethod); //创建了一个委托实例,要和方法关联起来
            d();
        }
        static void MyMethod()
        {
            Console.Write("委托方法");
        }
    }
    /// <summary>
    /// delegate 就是一种类型 定义了一个无参无返回值的委托,委托会对应具体的类型
    /// </summary>
    public delegate  void MyDelegate();
    /// <summary>
    /// 声明了一个类型
    /// </summary>
    class Test 
    {
        //类的成员
    }
}
View Code

相关文章:

  • 2021-07-30
  • 2021-06-15
  • 2021-05-22
  • 2021-12-12
  • 2021-08-03
  • 2021-05-28
猜你喜欢
  • 2022-12-23
  • 2021-12-17
  • 2021-05-10
  • 2021-11-28
  • 2022-02-08
  • 2021-08-02
  • 2021-06-17
相关资源
相似解决方案