In C # or that. NET event-handling mechanism, there are three key concepts-Events (event), delegate (Delegate) and processor (Handler), in addition to the object-oriented background, there are two other concepts-sender (Sender), receiver (receiver).
Both sender and receiver are easy to understand, while the previous 3 are confusing, and the following content attempts to explain and clarify them.
An event is usually a property of a class instance that can be raise. When it is raise, the processor (Handler) that is bound to the event attribute is called, and the processor is usually a function with a specific signature.
A delegate (Delegate) is a type that is used to define the event properties. The object associated with the event property is sender, which is usually the first parameter of the handler call, and the object associated with the called handler function is receiver.
In C #, the event keyword is used for the declaration of a property of events so that event properties can be distinguished from the general attribute as the first class element in the language.
In the following example:
Sent, is the event property
Eventhandler<eventargs>, is the delegate type
public void Handler (object sender, EventArgs e), is a processor function
2015-03-06
The relationship between Event,delegate,handler