C #, understanding of delegation and events

Source: Internet
Author: User
Delegate:
1. delegate is the function pointer. Type-safe function pointer (this restriction is not found in C)
2. A delegate can be considered as a method signature of a certain type. This type is only applicable to the return value and method parameters. That is, the method parameter format, sequence, number, and return type are the same, regardless of its static/instance, public/private/Internal /..., it can be defined as a type of Delegate (called by the delegate), that is, the delegate instance, so there is no static, in its Declaration
3. Delegate inheritance structure: DeleGate <-- system. multicastdelegate <-- system. Delegate. When a multicast delegate is used, the delegate type must be void (because the return type of each delegate method is unknown)
4. The methods in multicast delegation are called in sequence (FIFO), so it is best to have no dependency between methods.

Event:
1. The event depends on the delegate, which processes the eventProgramRegister with the delegate.
2. events can be associated with multiple delegates (instances of the same type). These delegates have no execution sequence. Of course, the event handler is also of the void type.

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.