The following is the standard way to define a delegate:
public delegate void PhoneRangHandler ( object sender, EventArgs e ); public event PhoneRangHandler PhoneRang;
To decouple the method(s) called from the calling code. It allows the designer of an object to define the delegate, and the user of the object to define which method will be called when the delegate is invoked.
You instantiate a delegate like this:
OnPhoneRings myDelegate = new OnPhoneRings(myMethod);
Here is how to call a delegated method:
OnPhoneRings(object this, new EventArgs( ));
The ability for more than one method to be called through a single delegate.
Limits the use of the delegate in the following ways:
You can only add a method using
You can only remove a method using
The delegate can only be invoked by the class that defines it.
Define the delegate to take, as its second parameter, an
object of a type derived from
EventArgs. Pass the information
through properties of that object.
Rather than creating a method that matches the delegate’s signature and then assigning the name of that method to the delegate, you can directly assign an unnamed delegate method by providing the implementation in line ...