可能重复:
Storing a reference to an object in C#我可以在对象中存储对变量的引用吗?
是否有存储在一个类对象的引用的方法吗?类似于:
public class X
{
public X(ref int i)
{
_t = i;
}
public void f(int ii)
{
_i = ii;
}
private int ref _i;
}
// ...
int i = 0;
X x = new X(ref i);
x.f(42);
// i is now 42
在C++中,我会用指针或引用来做到这一点。
你能解释一下你想达到什么吗? – 2011-03-28 18:55:26
@Rafał:我以为我做到了。我想要一个类对象引用一个存储在别处的对象,这样类成员函数所造成的变化就会反映在这个外部对象中。 – sbi 2011-03-28 18:58:33
*另请参阅[.net - 存储对C#对象的引用](http://stackoverflow.com/questions/2760087/storing-a-reference-to-an-object-in-c)* – 2011-03-28 18:59:00