1、基础使用
public delegate string Dele(string name);
public static string English(string name)
{
return "Good Morning" + name;
}
public static string Chinese(string name)
{
return "早上好" + name;
}
public static string GreetPeople(string name, Dele dele)
{
return dele(name);
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = GreetPeople("张三", Chinese);
label2.Text = GreetPeople("Jack", English);
}
private void button2_Click(object sender, EventArgs e)
{
Dele d1 = English;
Dele d2 = Chinese;
label1.Text = GreetPeople(" 李四", d1);
label2.Text = GreetPeople(" Bob", d2);
}
private void button3_Click(object sender, EventArgs e)
{
Dele d1=English;
d1 += Chinese;
label3.Text = d1("王五");
}
private void button4_Click(object sender, EventArgs e)
{
Dele de1 = new Dele(English);
de1 += Chinese;
de1 += English;
label1.Text = GreetPeople(" 中文", de1);
de1 -= English;
label2.Text = GreetPeople("还是中文", de1);
}