s*******k 发帖数: 20 | 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. | k****i 发帖数: 1072 | 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.
| w**w 发帖数: 5391 | 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() : {
| s*******k 发帖数: 20 | 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?
|
|