C#委托最简单的示例!

来源:互联网 发布:网络砍价师 编辑:程序博客网 时间:2024/05/17 08:06
public class People{    public delegate void SayHello(String otherName);//定义一个用来和别人打招呼的委托    //和英国人打招呼    public void HelloInEnglish(String otherName)    {        Console.WriteLine("Hello : " + otherName);    }    //和中国人打招呼    public void HelloInChinese(String otherName)    {        Console.WriteLine("你好 : " + otherName);    }    //对外公开的方法,传一个委托进来,就可以根据这个委托和别人打招呼了    public void Hello(SayHello hello, String otherName)    {        hello(otherName);    }    public static void Main()    {        People Shiori = new People();        Shiori.Hello(Shiori.HelloInChinese, "张三");        Shiori.Hello(Shiori.HelloInEnglish, "Jim");    }}


1 0