Using system;
Namespace consoleapplication3 {public delegate void myDelegate (String STR);
Class class1 {private static void Hello (String str) {console.writeline ("Hello" str);}
Private static void goodbye (string str) {console.writeline ("Goodbye" Str);}
Static void main (string [] args) {MyDelegate A, B, C, D; a = new mydelegate (hello); b = new mydelegate (goodbye); c = a b; D = C - a; A (" A "); b (" b "); c (" c "); d (" d ");
Console.readline ();}}}
My understanding is that delegate is a function of a function, which is essentially a function, which requires the return value and parameter list of the function when binding, must meet the requirements of Delegate declaration.
At this time, I will compare Event.
This.Load = new system.eventhandler (this.page_load); very clear, this.Load is an event, also a delegate, and System.EventHandler () is also a delegate, and his return value The parameter list and this.load are the same. At this time, Page_Load is a specific function bound by System.EventHandler, which is the same as the return value and parameter list of the top. When this.Load event happens, triggered the new NEW SYSTEM.EVENTHANDLER, thereby running Page_Load.
Found an example, event handling
Using system;
Public class eventtest {public delegate void myeventhandler (Object Sender, System.EventArgs E);
Public Static Void MyEventFunc (Object Sender, System.EventArgs E) {Console.writeLine ("My Event IS DONE!");}
PRIVATE EVENT MyEventHandler MyEvent;
Public evenstest () {
This.Myevent = new myeventhandler (myEventfunc);
Public void raiseevent () {Eventargs E = New Eventargs (); if (myEvent! = null) MyEvent (this, e);}
Public static void main () {EVENTTEST ET = New EventTest (); Console.Writeline ("please INPUT A"); if (console.readline () == "a") et.raiseevent (); elseconsole.writeline Error ");}}