// This method is called to execute the multicate delegate // object. public static void ExecuteDelegate(Greeting greetings) { if (null != greetings) { foreach (Greeting g in greetings.GetInvocationList()) { int result = g(); Console.WriteLine("\t Result = {0}.\n", result); } } }
static void Main(string[] args) { string name = "User1"; //Greeting greeting = null; Greeting greeting = new Greeting(Program.Hello); greeting -= Hello; //greeting += Привет; Console.WriteLine(greeting.GetInvocationList()); greeting.Invoke(name); Farewell += Bye; Farewell += Пока; if (Farewell != null) { Farewell(name); } else { Console.WriteLine("I have no one to say goodbye to"); } Console.ReadLine(); }