110,538
社区成员
发帖
与我相关
我的任务
分享
namespace test_AssignOfReferenceType
{
public partial class Form1 : Form
{
public Test t;
public Form1 ()
{
InitializeComponent ();
}
private void toolStripButton1_Click (object sender , EventArgs e)
{
Test _t=new Test();
method (_t);
MessageBox.Show (t.str);
}
public void method (Test _t)
{
//t是引用类型,测试对它的赋值是否需要用new
//这里看来不需要用new,直接=复制就可以
//那么和用new来赋值有什么区别?
t = _t;
//t = new Test(_t);
}
}
public class Test
{
public string str;
public Test () { str = "xxx"; }
public Test (Test t) { str = t.str; }
}
}
public void method (Test _t)
{
//t是引用类型,测试对它的赋值是否需要用new
//这里看来不需要用new,直接=复制就可以
//那么和用new来赋值有什么区别?
t = _t;
}