参考:http://zhidao.baidu.com/question/39151329.html
委托,也就是C语言里的函数指针;
//--在WindowApplication里写的
public delegate void MultiDelegate(string name); //--声明委托
public void First(String name) //--第一个方法
{
Console.Write(name + " first method!");
label1.Text = name + " first method!";
label1.Visible = false;
MessageBox.Show("first method!", "first method!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public void Second(String name)
{
Console.Write(name + "Second method!");
label1.Text = name + "Second method!";
label1.Visible = true;
}
private void button1_Click(object sender, EventArgs e) //--使用委托
{
MultiDelegate dl = new MultiDelegate(First);
dl += new MultiDelegate(Second);
dl("hehe!"); //--先执行First方法,马上接着执行Second方法
}