Events are also methods.
Defining an event member means that the type has three capabilities:
* Static method/instance method of type can subscribe to type event
* Static method/instance method of type can unregister type event
* methods to notify subscribed events when events occur
. The NET2.0 event is still based on Win32, but it is implemented using the observer pattern, and is built on the delegate mechanism.
The design steps for the event are as follows (basically the observer implementation steps):
10.1 Design an external type of event
1. Define eventargs or subclasses to store additional information:
Defines a class that inherits from EventArgs, ends with EventArgs, and contains a set of private fields and corresponding read-only public properties.
public class Newmaileventargs:eventargs
{
private string from;
public string from
{to
}
}
}
Here, the EventArgs base class looks like this in FCL:
[Serializable]
[ComVisible (True)]
public class EventArgs
{
//Summary:
//Indicates an event with no event data. Public
static readonly EventArgs Empty;
public EventArgs ();
}
Most events do not have data attached, so you do not have to define any private fields and properties and use the EventArgs base class directly as parameters.