avatar
Reference type问题# DotNet - 窗口里的风景
j*o
1
Class是Reference Type. 怎么才能只传递值?以一个简单的TextBox为例:
TextBox txtBox2 = new TextBox();
txtBox2.Text = "2";
TextBox txtBox3 = txtBox2 ;
txtBox3.Text = "3";
MessageBox.Show(txtBox2.Text); // 怎么才能够输出2?
谢谢!
avatar
m*t
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?
: 谢谢!

avatar
j*o
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.

avatar
m*t
4

Not any I know of. 8-)
Except, of course, you make a copy of txtBox2 first...

【在 j*****o 的大作中提到】
: 有什么办法在用txtBox2给txtBox3付值得时候,不传递txtBox2的reference, 而只是传递
: txtBox2的值?
: 谢谢。

avatar
j*o
5
怎么叫make a copy? 谢谢。

传递

【在 m******t 的大作中提到】
:
: Not any I know of. 8-)
: Except, of course, you make a copy of txtBox2 first...

avatar
m*t
6
I meant literally make another text box, and call it txtBox3.

【在 j*****o 的大作中提到】
: 怎么叫make a copy? 谢谢。
:
: 传递

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。