Type compatibility
Question: In spite of the difference between value types and
reference types all .NET types are compatible with
System.Object . How is this compatibility achieved for
value types?
Answer: see 3.2.4 From Value Type to Reference Type and Back
This compatibility is achieved through a mechanisms known as "Boxing":
Objects of values types are copied into structure equivalent
reference type objects on the heap and a reference to the result is
stored in the reference type variable.
Such "boxed" value type objects can then be reassigned to value
type variable and thus copied to the stack.
|