多播委托
#region 多播委托
//多播委托就是委托里面包含多个方法 按顺序调用
//多播委托里面包含一个逐个调用的委托集合 其中一个委托异常就会立即终止
static void Main(string[] args)
{
Action action = Test111; ;//Action委托 : 封装Test111方法 被封装的方法不具有参数且不能有返回值
action += Test112;//action = action + Test112
//action -= Test112;//action = action - Test112
+=就是在委托里面添加新的方法
- =就是在委托里面移除一个方法
//action();//运行委托
Delegate[] delegates = action.GetInvocationList();//GetInvocationList按顺序返回委托列表用Delegate委托数组来接收
foreach (Delegate d in delegates)
{
d.DynamicInvoke();//DynamicInvoke动态调用delegates中的方法 和action();差不多
}
}
private static void Test111()
{
Console.WriteLine("Test111");
}
private static void Test112()
{
Console.WriteLine("Test112");
}
#endregion