The type of your variables is a reference type
System.Object
(and
object
is an alias in language), a common base of all types. What happens with primitive types like integers?
Working with reference types, you store two objects: the variable itself stored in a variable, and the reference points to some object stored in heap. When you assign, reference is changed, object is not.
A variable has some
compile-time type which never changes and is defined only by a declaration.
Its compile-time type never changes, but run-time type can be changed during run time. All variable of the type
System.Object
are
assignment-compatible with any type (on the right of the assignment operator), but non-reference types are
boxes, see
http://en.wikipedia.org/wiki/Boxing_%28computer_science%29#Boxing[
^],
http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx[
^].
Here is what happened:
In fist line, a boxed form of 5 is created and assigned to
d
.
In second line,
h
is done referentially equal to
d
. You obtain one single boxed form of 5 referenced by the two variables.
In third line, a boxed form of 9 is created and assigned to
d
.
It created a brand new reference, not modified a previously created boxed form.
Assignment to variable of reference types in general case change the reference, not the value of anything.
The boxed object is
immutable from the standpoint of the language, but in principle you can modify it using Reflection.
—SA