- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ConsoleApplication1
- {
- class BroadCastDelegate
- {
- public static void Printf(string Msg)
- {
- Console.WriteLine(Msg);
- }
- public void Method1(string Msg)
- {
- Console.WriteLine(Msg);
- }
- public void Method2(string Msg)
- {
- Console.WriteLine(Msg);
- }
- }
- public class B
- {
- public delegate void ShowMsg(string Msg);
- public static void Main()
- {
- ShowMsg objShowMsg = BroadCastDelegate.Printf;
- ShowMsg objShowMsg1 = (new BroadCastDelegate()).Method1;
- ShowMsg objShowMsg2 = (new BroadCastDelegate()).Method2;
- ShowMsg allShow = objShowMsg1 + objShowMsg2;
- allShow += objShowMsg;
- objShowMsg("Static Method");
- objShowMsg1("Msg 1");
- objShowMsg2("Msg 2");
- allShow("Static Method");
- Console.ReadLine();
- }
- }
- }
注意他们的执行顺序。多播委托以先后为顺序