You cannot store variable references in .NET, period. You can store references to objects, but not reference variables.
, , . , , , .
, , . ( ) "a" " " ( ) "a" " int variable". , int " ", . , , ; ; int .
, , , , , ?
. , , .
, , int, , . , .
, .
void M(ref int y) { y = 123; }
...
int x = 0;
M(ref x);
: "x y - ".
, , , " , , ", :
class Ref<T>
{
private Func<T> getter;
private Action<T> setter;
public Ref(Func<T> getter, Action<T> setter)
{
this.getter = getter;
this.setter = setter;
}
public T Value
{
get { return getter(); }
set { setter(value); }
}
}
...
int abc = 123;
var refabc = new Ref<int>(()=>abc, x=>{abc=x;});
... now you can pass around refabc, store it in a field, and so on
refabc.Value = 456;
Console.WriteLine(abc);
Console.WriteLine(refabc.Value);
?