一个多播委托

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace ConsoleApplication1
  5. {
  6.     class BroadCastDelegate
  7.     {
  8.         public static void Printf(string Msg)
  9.         {
  10.             Console.WriteLine(Msg);
  11.         }
  12.         public void Method1(string Msg)
  13.         {
  14.             Console.WriteLine(Msg);
  15.         }
  16.         public void Method2(string Msg)
  17.         {
  18.             Console.WriteLine(Msg);
  19.         }
  20.     }
  21.     public class B
  22.     {
  23.         public delegate void ShowMsg(string Msg);
  24.         public static void Main()
  25.         {
  26.             ShowMsg objShowMsg = BroadCastDelegate.Printf;
  27.             ShowMsg objShowMsg1 = (new BroadCastDelegate()).Method1;
  28.             ShowMsg objShowMsg2 = (new BroadCastDelegate()).Method2;
  29.             ShowMsg allShow = objShowMsg1 + objShowMsg2;
  30.             allShow += objShowMsg;
  31.             objShowMsg("Static Method");
  32.             objShowMsg1("Msg 1");
  33.             objShowMsg2("Msg 2");
  34.             allShow("Static Method");
  35.             Console.ReadLine();
  36.         }
  37.     }
  38.            
  39. }

注意他们的执行顺序。多播委托以先后为顺序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值