avatar
Question about struct# DotNet - 窗口里的风景
s*k
1
[quote]Within an instance constructor of a struct, "this" corresponds to an
out parameter of the struct type, and within an instance function member of a
struct, "this" corresponds to a ref parameter of the struct type. In both
cases, this is classified as a variable, and it is possible to modify the
entire struct for which the function member was invoked by assigning to "this"
or by passing this as a ref or out parameter.[/quote]
Not quite get it.
Would any DX help with some intances?
Thanks.
avatar
k*i
2
struct MyStruct
{
int x, y;
public MyStruct(int x, int y)
{
this.x = x;
this.y = y;
}
public void Change()
{
this=new MyStruct(1,1);
Print();
}
public void Print()
{
System.Console.WriteLine(this.x);
}
}
Remember, "this" is a value in class

a
this"

【在 s*******k 的大作中提到】
: [quote]Within an instance constructor of a struct, "this" corresponds to an
: out parameter of the struct type, and within an instance function member of a
: struct, "this" corresponds to a ref parameter of the struct type. In both
: cases, this is classified as a variable, and it is possible to modify the
: entire struct for which the function member was invoked by assigning to "this"
: or by passing this as a ref or out parameter.[/quote]
: Not quite get it.
: Would any DX help with some intances?
: Thanks.

avatar
w*w
3
can you explain how to know this in class is a value type?

【在 k****i 的大作中提到】
: struct MyStruct
: {
: int x, y;
: public MyStruct(int x, int y)
: {
: this.x = x;
: this.y = y;
: }
: public void Change()
: {

avatar
s*k
4
My understanding is:
"this" in class is a value, not a variable; while in struct, it is a variable,
which represents a storage location, mostly likely the containing variable
itself.
Am I right?
Further question regarding "this is a value in class": What is the value of
this in class then?

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