must not point to the same part of memory on the heap after assigning obj = name
Yes. They both refer to the same string instance. You can see this by calling:
bool sameStringReference = object.ReferenceEquals(obj, name);
However, as soon as you do this:
obj = "joe";
You change this so that obj now refers to another line. name will still refer to the original string, however, since you did not reassign it.
If you then do:
sameStringReference = object.ReferenceEquals(obj, name); // Will be false
At this point, it will be wrong.
source share