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.
|