我正在使用C#开发一个需要两种形式的项目;一个要填写,另一个要显示填写的内容。问题是,我不确定这两组代码中哪一个对编译器更有效,并且占用更少的RAM,因为它们在执行方面都非常不同。
这是第一个例子:
方法一:
表格1
targetSandboxVersion
表格2
Form1 frm1;
Form2 frm2;
public Form1()
{
InitializeComponent();
//Currently, I have instantiated an object of the current form.
frm1 = this;
}
private void btn_Click(object sender, EventArgs e)
{
//From there, I pass it into the second form.
frm2 = new Form2(frm1);
frm2.ShowDialog();
}
这是第二组的一个例子:
表格1:
From1 frm1;
public Form2(Form1 frm1)
{
InitializeComponent();
this.frm1 = frm1;
}
//From here, I would make the change to the first form. For example:
private void btn_Click(object sender, EventArgs e)
{
frm1.listbox.Items.Add("string");
}
表格2
Form2 frm2;
public Form1()
{
InitializeComponent();
}
private void btn_Click(object sender, EventArgs e)
{
//Here, I pass in an existing listbox to the next form.
frm2 = new Form2(listbox);
frm2.ShowDialog();
}
有什么建议吗?