This is not how variables work in C #. This has nothing to do with the types of boxing values.
Consider this:
object o1 = new object(); object o2 = o1; o2 = new object();
Why do you expect o1 and o2 to contain a link to the same object? They are the same if you set o2 = o1 , but after setting o2 = new object() value changes (memory location, which the variable points to) o2 .
Perhaps what you are trying to do can be done as follows:
class Obj { public int Val; } void Main() { Obj o1 = new Obj(); o1.Val = 5; Obj o2 = o1; o2.Val = 8; }
At the end of Main Val o1 property will contain 8 .
source share