C # events-what is an event

Source: Internet
Author: User

Every day, all kinds of news and events are happening around us. There are unpleasant events: breaking up with our girlfriend, losing our country football, plane crash, Haiti earthquake ...... There are also lucky events: Shen Xue, Zhao Hongbo, won the championship after the exam scored a high score ...... And so on.

What is an event?

This problem has plagued me a lot. in C # advanced programming version 6th, the event is said as follows: the event represents an object defined in C, the object that processes the notification process. However, this is not abstract, and it is difficult for beginners like me to understand it. In my understanding, events are the objects that process events that are interested in. They can perceive or capture changes in the state of a thing. To put it bluntly, events are changed. In philosophy, the movement of things is eternal, and the rest is relative. The eternal movement means that things are changing. So all the time, the world and the universe in which we live are changing infinitely. However, the vast majority of these events are not an event for you. If the president of Peru is dead, it may be an event for all the people in Peru because of their concern, however, if you are not familiar with the lectures in the classroom, this change is an event for you unless you have heard such a news and started to pay attention to it. So, in all these changes, the changes that you can capture and are interested in are an event for you.

So what if we put the concept of event into program design? It is actually the same. In the same way, as long as the machine is on, the hardware and software in the machine will change their status. But for the code you want to write, not all of these changes are events. The events you need are only a small part of your interest in these changes. You only need to find the state change you are interested in and be able to capture it, you can use the event processing model to complete what you want to do.

An event is actually a message. In WINDOWS, it is message-driven and called an event in C #. in C #, processing an event is done by Delegate, you must first understand the delegate to better understand the event. An event is a Special Delegate class.

An event, such as a Click event, is essentially a method (a function) to be executed, and C # indirectly calls a method by defining the delegate. Therefore, when defining events, you must first define the delegate. The reason why we can directly write the Click method of controls (such as buttons) Is that vs has defined the events and delegation of these commonly used controls, so we can simply write the Click Event method.
If we define an event, we must define the delegate used for this event at the same time, and then write the delegate call method.

 

Note: This article is reproduced, the original source http://panjunlai.blog.163.com/blog/static/581903012010420788671/

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.