var a = MyClassInstance;
MyClassInstance = null;
//if (a !=null){ //why }
I think that a
points to MyClassInstance
and MyClassInstance
equals null, then a
must be equals null too. But a
is not null and I don't understand why.
a
and MyClassInstance
are references to an object.
Changing one reference doesn't change the other.
var a = MyClassInstance; // Both references point to the same object
MyClassInstance = null; // MyClassInstance now points to null, a is not affected
The variable a
is a reference, so the value it holds is the "location" of some object. MyClassInstance
is also a reference. By setting a = MyClassInstance
they both point to the same instance. Setting MyClassInstance
to null affects that reference only. It doesn't affect the object itself and it doesn't affect any other references.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With