Lesson 10 on Event CLR

Source: Internet
Author: User

I. Events: Allow objects to register events; allow objects to log off events, allow objects defining events to maintain a collection of registration objects, and

These objects are notified when a specific event occurs.

CLR events are built on the delegate (delegate.

2. events can only be registered or canceled by the event type. An event is actually a static function.
3. Events are inherited from sysetm. eventargs. The naming rule is that events should end with eventargs. The delegate should end with eventhandler

Tail. This is the Naming Standard.

4. The essence of an event is delegation. When defining an event, the C # compiler will generate a private field of the delegate type and an add _ + event name,

The remover _ + two public methods of the event name. One event is used for registration and the other is used for event cancellation. Both methods have a Commission

Parameters of the carrier type. They use the combine and remove methods of delegae respectively.

5. Use + = to register the event and-= to cancel the event. You can also display the registration and cancellation methods for defining events, with high efficiency and no need to add

Contains redundant events, because sometimes we only need a few events, but the compiler will automatically load all the events required for delegation, resulting in performance

Lower. Disadvantage implementation is troublesome.

Vi. event registration set: it is a hashtale method, and an indexer is used to register events. In CLR

The system. componmentmodel. eventhanhlerlist type is used as the event registration set.

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.