Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Install and UnInstall message methods in the Messenger class.Lecture 6 - slide 9 : 20
Program 1
using System;

public delegate void Message(string txt);  

public class Messenger{
  
  private string sender;
  private Message message;  

  public Messenger(string sender){  
   this.sender = sender;
   message = null;
  }

  public Messenger(string sender, Message aMessage){  
   this.sender = sender;
   message = aMessage;
  }

  public void InstallMessage(Message mes){  
   this.message += mes;                     
  }   

  public void UnInstallMessage(Message mes){  
   this.message -= mes;                       
  }   

  public void DoSend(){                       
   message("Message from " + sender);         
  }
}
 
 
The delegate Message. A type.
 
 
 
 
The encapsulated delegate.
 
A constructor
 
 
 
 
Another constructor
 
 
 
 
A method that inserts a message (a method) 
in the encapsulated delegate.
 
 
A method that removes a message (a method) 
from the encapsulated delegate.
 
 
A method that activates all the methods in
the delegate.