The concept of events has been revisited today, and the understanding of events has been more profound. The final event is a special delegate. When we define an event, once we trigger the event, it means that we are invoking a series of methods behind it. We know that a delegate or an anonymous function (an anonymous method and a lambda expression) is a delegate that passes a method parameter to meet our requirements. If we have to deal with a function that requires some sort of action to be done, it means that we need to pass a number of methods, and we have to do it in a certain order, we can use the event. In other words, once we have bound a series of methods of an event, when the event is triggered, some of the methods will be executed in a smooth succession. In order to better complete the function.
Needless to say, I believe that programmers have a sense of the code of intimacy, see the code more to appreciate its beauty. Here are a few lines of short code to illustrate the problem:
public partial class Form1 : Form { public form1 () { initializecomponent (); //subscription events, binding with two methods (Message1 and Message2) smg += new showmessage ( Message); smg += new ShowMessage (Message1); } //declares a delegate that specifically delivers messages smg public event showMessage smg; private void message () { messagebox.show ("What's Your Name"); } private Void message1 () { messagebox.show ("My name is Xiao Kai"); } private void button1_click (Object sender , eventargs e) { //directly invokes the event, triggering the SMG event. Complete the execution of the two sentences.             SMG (); }
Custom events are as simple as this. The key still can be applied to the actual ... Come on!
C # Custom Events