Using system;
Using system. Collections. Generic;
Using system. text;
Namespace delegate {
// Define the delegate, which defines the types of methods that can be represented
Public Delegate VoidGreetingdelegate (StringName );
Class program {
Private Static void englishgreeting (string name ){
Console. writeline ("Morning," + name );
}
Private Static void chinesegreeting (string name ){
Console. writeline ("good morning," + name );
}
// Note that this method accepts a greetingdelegate method as a parameter.
Private Static void greetpeople (string name, greetingdelegate makegreeting ){
Makegreeting (name );
}
static void main (string [] ARGs) {
greetpeople ("Jimmy Zhang", englishgreeting);
greetpeople ("Zhang Ziyang", chinesegreeting );
console. readkey ();
}< BR >}< br> the delegate is a class that defines the type of the method, this allows the method to be passed as a parameter of another method. In this way, the method is dynamically assigned to the parameter, you can avoid using the IF-else (switch) Statement extensively in the Program , and make the program more scalable.