我一直在阅读有关在 C# 中传递引用类型的内容,但我不确定具体情况。
示例代码:
public class Foo
{
int x;
public SetX(int value)
{
x = value;
}
public int Zed
{
get;
set;
}
public class Bar : Foo
{
//suffice it to say, this is SOME inherited class with SOME unique elements
}
...
void Func (Foo item)
{
Bar child = item as Bar;
child.Zed = 2;
child.SetX(2); //situation in question.
}
...
Bar y = new Bar();
y.Zed = 1;
y.SetX(3);
Func(y);
我知道那Zed
没有改变,y
但被x
修改了?还是在传递到并将其视为一个之后x
仍然存在?3
y
Func
Bar