j*****o 发帖数: 320 | 1 Class是Reference Type. 怎么才能只传递值?以一个简单的TextBox为例:
TextBox txtBox2 = new TextBox();
txtBox2.Text = "2";
TextBox txtBox3 = txtBox2 ;
txtBox3.Text = "3";
MessageBox.Show(txtBox2.Text); // 怎么才能够输出2?
谢谢! |
m******t 发帖数: 2416 | 2
You can't. By the fourth line above, txtBox2.Text is already "3".
Note txtBox3 is referencing the same object as txtBox2. This does
not have to do with passing by ref or value.
【在 j*****o 的大作中提到】 : Class是Reference Type. 怎么才能只传递值?以一个简单的TextBox为例: : TextBox txtBox2 = new TextBox(); : txtBox2.Text = "2"; : TextBox txtBox3 = txtBox2 ; : txtBox3.Text = "3"; : MessageBox.Show(txtBox2.Text); // 怎么才能够输出2? : 谢谢!
|
j*****o 发帖数: 320 | 3 有什么办法在用txtBox2给txtBox3付值得时候,不传递txtBox2的reference, 而只是传递
txtBox2的值?
谢谢。
【在 m******t 的大作中提到】 : : You can't. By the fourth line above, txtBox2.Text is already "3". : Note txtBox3 is referencing the same object as txtBox2. This does : not have to do with passing by ref or value.
|
m******t 发帖数: 2416 | 4
Not any I know of. 8-)
Except, of course, you make a copy of txtBox2 first...
【在 j*****o 的大作中提到】 : 有什么办法在用txtBox2给txtBox3付值得时候,不传递txtBox2的reference, 而只是传递 : txtBox2的值? : 谢谢。
|
j*****o 发帖数: 320 | 5 怎么叫make a copy? 谢谢。
传递
【在 m******t 的大作中提到】 : : Not any I know of. 8-) : Except, of course, you make a copy of txtBox2 first...
|
m******t 发帖数: 2416 | 6 I meant literally make another text box, and call it txtBox3.
【在 j*****o 的大作中提到】 : 怎么叫make a copy? 谢谢。 : : 传递
|