Firstly, I'm assuming ZeroObject
is a class. If it's not, please disregard this answer.
when I do
B = A;
somewhere in the code,
B should have a reference of A, right?
Well, it means that B
will have the same value as A
. Any further changes to the value of A
(e.g. to make it refer to a different object) will have no effect on A
. If you change the data within the object that both A
and B
refer to, however, you'll be able to see that change through either reference.
Read my article on reference types and value types for more information.
is there a way to give C the reference of A without using
C = A;
in C#?
Well there are bizarre ways you could do it. For example:
public void SetValue<T>(out T target, T value)
{
target = value;
}
...
SetValue(out C, A);
... but it's unclear why you'd want to do this.