public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Person a,b,c= new Person (this);
a.say("abc");
}
}
public class Person
{
public Form1 MyForm;
public Person(Form1 form)
{
this.MyForm = form;
}
public void say(string w)
{
this.MyForm.chat.Text = this.MyForm.chat.Text+Environment.NewLine+w;
}
}
因此?
答案 0 :(得分:0)
您想通过创建对同一对象的三个引用来实现什么?只需将新Person
对象分配给a
即可。您可以在之后分配其他变量。
Person a, b, c;
a = b = c = new Person (this);
答案 1 :(得分:0)
这样做:
Person a,b,c= new Person (this);
仅实际初始化c
。您还需要显式初始化其他字段:
a = new Person(this);
b = new Person(this);