Basically, I get a reference to a field of an object that is stored inside an array and put that into a variable.
Then, I want to assign a different object reference to the field by assigning it to the variable I stored the field in earlier.
To illustrate my point, here's a simple example:
class myClass
{
public object obj = null;
}
class someOtherClass
{ }
...
static void Main(string[] args)
{
myClass[] arr = new myClass[] { new myClass() };
var objVar = arr[0].obj;
objVar = new someOtherClass();
}
I get the field from the object from the array and store it in a variable.
Now, I want to store a new value in the field by assigning the variable.
What actually happens though is that the variable does not keep the reference to the field, but rather just assigns the object of someOtherClass
to the variable, removing the field from the varible.
So after this code executed, field obj
of the myClass
instance is still null, while the variable objVar contains a reference to my someOtherClass
instance.
Is there an easy way to assign a reference to a reference inside a variable like this?