Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    An Application class.Lecture 6 - slide 9 : 20
Program 3
using System;

public class Application{

  public static void Main(){
    A a1 = new A(1),  
      a2 = new A(2),
      a3 = new A(3);

    Messenger m = new Messenger("CS at AAU", a2.MethodA);  
    m.InstallMessage(a1.MethodA);  
    m.DoSend();  
    Console.WriteLine();

    m.InstallMessage(a3.MethodA);   
    m.InstallMessage(a3.MethodA);
    m.DoSend();
    Console.WriteLine();

    m.UnInstallMessage(a3.MethodA);  
    m.UnInstallMessage(a1.MethodA);  
    m.DoSend();
 }
}
 
 
 
 
 
Three instances of class A.
 
 
 
The delegate is created to contain a2.MethodA.
Add a1.MethodA
Activates both a2.MethodA and a1.MethodA.
 
 
Etc...
 
 
 
 
Removes last instance of a3.MethodA.
Etc...