For me, I have always been confused. I have to read books and understand them again soon. Now I will record my understanding in white text.
Good article address: http://www.cnblogs.com/JimmyZhang/archive/2007/09/23/903360.html
1. Declare delegation.
A delegate is a class that defines the type of a method so that the method can be passed as a parameter of another method. This way, the method is dynamically assigned to the parameter, it can avoid using the IF-else (switch) statement in a large number in the program, and make the program more scalable.
A good way to understand the delegate is to treat the delegate as a name for the method signature and return type. Its syntax definition is similar to the method definition, but there is no method body, the method must match the delegate signature.
Definition
[Access modifier] delegate [return type] deleteagemethod (parameter). For example:
Public Delegate void invoke (INT parameter)
Usage:
In the static main () method, the method is declared as static.
// Delegate method public static void add (int x) {x = x + X; console. writeline ("auto-increment as" + x);} // delegate method public static void multi (INT y) {Y = y * Y; console. writeline ("multiplication is" + Y);}/* commissioned test */invoke voke = new invoke (Multi, you only need to delegate the instance to transfer the address name. This is called deleGATE inference. As long as the compiler can resolve the delegate security to a specific type, this C # feature is valid. for example, // invoke voke = multi; voke (4 );