简单多播委托Demo

 1 namespace ConsoleApp4
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             Mum mum = new Mum();
 8             Dad dad = new Dad();
 9             Son son = new Son();
10             Sister sister = new Sister();
11             mum.TellEat();
12             mum.EatDel += son.SonEat;
13             mum.EatDel += dad.DadEat;
14             mum.EatDel += sister.SisterEat;
15             mum.EatDel();
16             //最后执行这个委托即可
17             Console.ReadKey();
18         }
19     }
20     //定义一个无参无返的委托
21     public delegate void HaveEatDel();
22     public class Mum
23     {
24         public void TellEat()
25         {
26             Console.WriteLine("吃饭了");
27         }
28         //定义委托实例
29         public HaveEatDel EatDel { get; set; }
30     }
31     public class Son
32     {
33         public void SonEat()
34         {
35             Console.WriteLine("知道了,玩完游戏再去");
36         }
37     }
38     public class Dad
39     {
40         public void DadEat()
41         {
42             Console.WriteLine("就来!");
43         }
44     }
45     public class Sister
46     {
47         public void SisterEat()
48         {
49             Console.WriteLine("一会就来");
50         }
51     }
52 }

 

posted @ 2018-11-06 10:10  若青若墨  阅读(570)  评论(0编辑  收藏  举报