C#的委托案例
2021-01-17 06:16
标签:你好 mil ram 注释 mes ogr string rgs write C#实现(Delegate)的委托就不多说了,直接上代码,看代码中的注释: C#的委托案例 标签:你好 mil ram 注释 mes ogr string rgs write 原文地址:https://www.cnblogs.com/wml-it/p/12204098.htmlnamespace Delegate
{
delegate void DGSayiHi(string name);//声明委托
delegate void DGDo(string name);
class Program
{
static void Main(string[] args)
{
DGSayiHi sayhi = new DGSayiHi(SayChineseHi);
DGSayiHi sayhi2 = new DGSayiHi(SayEnglishHi);
sayhi += sayhi2;//实际上+=相当于Delegate.Combine, -=相当于Delegate.Remove
sayhi("春晓");
Console.ReadLine();
}
static void SayChineseHi(string name)
{
Console.WriteLine("你好:" + name);
}
static void SayEnglishHi(string name)
{
Console.WriteLine("Hello:" + name);
}
}
}