t2=t1;//变量t2的值是t1的引用
t2.Text="dddddddd";//实际是改变了t1的text
MessageBox.Show(t1.Name+" "+t1.Text);
MessageBox.Show(t2.Name+" "+t2.Text);
//输出的都是t1的属性
for(int i=0;i<this.Controls.Count;i++)
{
MessageBox.Show(this.Controls[i].Name+":text="+this.Controls[i].Text);//输出form里所有的control(button1,t1,t2)其中t1在上面已经改变,t2内容没有改变
}
}
t2.Text="dddddddd";//实际是改变了t1的text
MessageBox.Show(t1.Name+" "+t1.Text);
MessageBox.Show(t2.Name+" "+t2.Text);
//输出的都是t1的属性
for(int i=0;i<this.Controls.Count;i++)
{
MessageBox.Show(this.Controls[i].Name+":text="+this.Controls[i].Text);//输出form里所有的control(button1,t1,t2)其中t1在上面已经改变,t2内容没有改变
}
}
解决方案 »
- 无法加载 DLL“Mwic_32.dll”: 内存位置访问无效。 (异常来自 HRESULT:0x800703E6
- 关于绑定数据库
- 如何在根据datatable,正向循环在treeview中的节点下加入新的节点。。。
- 各位大侠,帮帮忙吧~!关于.net 附加进程的 小问题
- 什么时候用静态方法??
- 求高手解答?
- 急,只好借用此人气了:平台调用时,MFC的CStringArray在c#中,使用什么替代?
- web如何使用DataGrid单击某行的任一地方,选中该列?
- C# librtmp
- 删除图片文件出错
- 请问怎样把 Cursor转换为 IntPtr?
- .net下为什么要由它来管理内存?这样做有什么好处?
t2.Text = t1.Text;
t2. = t1;
t2.Text="dddddddd";
....
t2.Name=t1.Name;
t2.Text = t1.Text;
....or you have to use Reflection (you might need to use the overloaded GetProperties() to get the private properties) (didn't test, so it might not work):using System.Reflection;foreach (PropertyInfo pi in t2.GetType().GetProperties())
{
pi.SetValue(t2, pi.GetValue(t1,null),null);
}
private System.Windows.Forms.TextBox t1;
private System.Windows.Forms.TextBox t2;
private void button1_Click(object sender, System.EventArgs e)
{
t1 = t2;
...
}
也就是说,这里的t1和t2都是引用,而不是对象了??