The relationship between Event,delegate,handler

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.