public partial class Form1 : Form
{
public delegate void SayHelloDelegate(string name);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//SayHelloDelegate shd = new SayHelloDelegate(SayHello.SayHelloChinese);
SayHelloDelegate shd = SayHello.SayHelloChinese;
shd += new SayHello().SayHelloEnglist;
shd("李四");
//new SayHello().SayHelloAllLanguage("张三","C");
}
private void button2_Click(object sender, EventArgs e)
{
SayHelloDelegate shd = new SayHelloDelegate(new SayHello().SayHelloEnglist);
shd("李四");
//new SayHello().SayHelloAllLanguage("张三", "E");
}
}
以上代码中
//SayHelloDelegate shd = new SayHelloDelegate(SayHello.SayHelloChinese);
这行new后面的代码是什么意思
new 就是实例化的意思 在内存中分配了SayHelloDelegate 对象 并传参SayHello.SayHelloChinese
谢谢