码迷,mamicode.com
首页 > Windows程序 > 详细

C# 委托链、多路广播委托

时间:2017-05-23 18:47:53      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:ring   类型   color   class   strong   .com   运行   nbsp   分享   

委托链、多路广播委托:也就是把多个委托链接在一起,我们把链接了多个方法的委托称为委托链或多路广播委托

例:

 1 class HelloWorld
 2    {
 3       //定义委托类型
 4       delegate void DelegationChain();
 5       static void Main(string[] args)
 6       {
 7          //用静态方法来实例委托
 8          DelegationChain mydelegateone=new DelegationChain(HelloWorld.Fun2);
 9           //用实例方法来实例委托
10          DelegationChain mydelegatetwo=new DelegationChain(new HelloWorld().Fun1);
11          //定义一个委托对象初始化为null
12          DelegationChain delegationChain=null;
13           //使用‘+链接委托,链接后就成了委托链
14           delegationChain+=mydelegateone;
15           delegationChain+=mydelegatetwo;
16           //调用委托链
17           delegationChain();
18          Console.ReadKey();
19       }
20       private void Fun1()
21       {
22           Console.WriteLine("Fun1");
23       }
24       private static void Fun2()
25       {
26           Console.WriteLine("Fun2");
27       }
28    }

运行结果:

技术分享

 

C# 委托链、多路广播委托

标签:ring   类型   color   class   strong   .com   运行   nbsp   分享   

原文地址:http://www.cnblogs.com/lbonet/p/6895387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!