欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

简单多播委托Demo

程序员文章站 2022-09-04 11:50:07
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 ... ......
 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 }