学习简单的委托

来源:互联网 发布:建站数据库教程 编辑:程序博客网 时间:2024/05/21 07:59

public delegate int get1(int aaa, int bbb); 委托的声明

 public class DeleteGate {   声明  一个类,具有两个相同签名的方法。

 public int getSum(int a, int b)

{ return a + b; }

public int getJian(int a, int b) { return a - b; }

}

        static void Main(string[] args)
        {
            DeleteGate deleteGage = new DeleteGate();  //
            get1 get = new get1(deleteGage.getSum); //给委托 进行签名。

            System.Console.Write(get(100, 10)); //然后就能使用委托,实现方法的功能。
            System.Console.Read();
        }

原创粉丝点击