C # implement the standard event processing procedure in three steps

Source: Internet
Author: User

 

Event. MSDN explains: classes or objects can notify other classes or objects of related events through events. The class for sending (or triggering) events is called "publisher", and the class for receiving (or processing) events is called "subscription ". We will not talk nonsense about the theory and benefits of events here. If you are interested, please refer to the MSDN explanation. Here is a demo to demonstrate how to implement standard event processing step by step. It can be used as a reference for writing events in future code. To use events, you need to know about delegation and events. You can go to relevant tutorials. The simulation has a horrible arms provider asking us to implement a Rocket Gun order management program. : Step 1: Let's take a look at the event description on MSDN in basic practice. We may want to practice it to compile a simple event processing, which is neither parameter nor standard, but the event implementation function has been achieved. Code
1 publicclass BookBomb
2 {
3 /// <summary>
4 // define Delegation
5 /// </summary>
6 publicdelegatevoid BookBombs ();
7 /// <summary>
8 // define an event
9 /// </summary>
10 publicevent BookBombs Book;
11 publicevent BookBombs Booking;
12 publicevent BookBombs Booked;
13
14 /// <summary>
15 // reservation
16 /// </summary>
17 publicvoid OnBook ()
18 {
19 if (Book! = Null)
20 {
21 Book ();
22}
23}
24 /// <summary>
25 // Processing
26 /// </summary>
27 publicvoid OnBooking ()
28 {
29 if (Booking! = Null)
30 {
31 Booking ();
32}
33}
34 /// <summary>
35 // Assembly completed
36 /// </summary>
37 publicvoid OnBooked ()
38 {
39 if (Booked! = Null)
40 {
41 Booked ();
42}
43}
44}
45}
This is an example of a very basic and non-standard event. It realizes three steps: Order booking, assembly processing, and assembly. Registering an event is simple. After the event name is entered + =, you will be prompted to press the Tab key to automatically import the corresponding processing programs for each event.
Related Article

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.