//public MarkGreeting delegate1; public void GreetPeople(string name, MarkGreeting delegate1) { //如果有方法注册委托变量 if (delegate1 != null) { delegate1(name);//通过委托调用方法 } }
static void Main(string[] args) { string chineseName = "小王"; string englishName = "neil"; MarkGreeting markGreeting1 = ChineseGreeting; MarkGreeting markGreeting2 = EnglishGreeting; //MarkGreeting mark2Greeting2 = EnglishGreeting; markGreeting1(chineseName); markGreeting2(englishName); //markGreeting1(englishName); Console.ReadKey(); }
public static void GreetPeople(string name, MarkGreeting markGreeting) { markGreeting(name); }