Using system; <br/> using system. collections. generic; <br/> using system. text; <br/> namespace consoleapplication2005 <br/>{< br/> // What is the delegate? The meaning of this name has given us the space we imagined. You are programming, <br/> // you are writing an ASP. net web page, and JS is not familiar to you, <br/> // you entrust a colleague to help you complete the JS part. This is the Commission. <br/> // you can leave what you cannot do to others. But how do I know who is going to do it? <Br/> // you must know the name! To distinguish people with the same name, a feature must be described. <Br/> // in C #, the delegate function is described as follows: delegate is like a function pointer, <br/> // different functions can be called when the program is running. <Br/> // This is actually the same as entrusting a colleague to complete the JS Code. <Br/> // If two colleagues can do this, they only need to make the results meet your needs (just like an interface ), <br/> // although they have different processes and different effects, they can meet your requirements. <Br/> Public Delegate void processdelegate (string S1, string S2); <br/> Public Delegate void processdelegatelist <t, s> (T S1, s S2 ); <br/> Public Delegate void evnentdelegate (Object sender, eventargs E); <br/> class Program <br/>{< br/> static void main (string [] ARGs) <br/> {<br/> // simple DeleGate <br/> processdelegate process = new processdelegate (new test (). appendstr); <br/> console. writeline ("simple delegate"); <B R/> process ("hello", "World! "); <Br/> // generic DeleGate <br/> processdelegatelist <string, int> processlist = new processdelegatelist <string, int> (New testlistdelegate (). appendstr); <br/> console. writeline ("generic delegate"); <br/> processlist ("Panda", 1); <br/> // when something happens, one object can notify another object through events. <Br/> // For example, if the front-end interface is completed, it notifies you that the front-end can be integrated with the program you developed. <Br/> // This is an event. It can be seen that an event triggers another task at a time node. <br/> // but how to do another task does not concern him. In terms of events, the key point is when and who will do it. <Br/> // event DeleGate </P> <p >}< br/> class test <br/>{< br/> Public void appendstr (string S1, string S2) <br/>{< br/> console. writeline (S1 + S2); <br/>}< br/> Public void sbustringlength (string S1, string S2) <br/>{< br/> // long to code .. <br/> console. writeline (s1.length + s2.length); <br/>}< br/> class testlistdelegate <br/>{< br/> Public void appendstr (string S1, int S2) <br/>{< br/> console. writeline (S1 + S2); <br/>}< br/> class eventdelegate <br/>{< br/> private string name1; <br/> Public String name1 <br/>{< br/> get {return name1 ;}< br/> set {name1 = value ;} <br/>}< br/> private string name2; <br/> Public String name2 <br/>{< br/> get {return name2 ;} <br/> set {name2 = value ;}< br/>}</P> <p>}