2010-03-30 Jb Evain <jbevain@novell.com>
[mcs.git] / docs / ecma334 / 18.3.5.xml
blob17d6a5cbec6cd965226e0dd530d7b1eaad4070fc
1 <?xml version="1.0"?>
2 <clause number="18.3.5" title="Boxing and unboxing">
3   <paragraph>A value of a class type can be converted to type object or to an interface type that is implemented by the class simply by treating the reference as another type at compile-time. Likewise, a value of type object or a value of an interface type can be converted back to a class type without changing the reference (but of course a run-time type check is required in this case). </paragraph>
4   <paragraph>Since structs are not reference types, these operations are implemented differently for struct types. When a value of a struct type is converted to type object or to an interface type that is implemented by the struct, a boxing operation takes place. Likewise, when a value of type object or a value of an interface type is converted back to a struct type, an unboxing operation takes place. A key difference from the same operations on class types is that boxing and unboxing copies the struct value either into or out of the boxed instance. <note>[Note: Thus, following a boxing or unboxing operation, changes made to the unboxed struct are not reflected in the boxed struct. end note]</note> </paragraph>
5   <paragraph>For further details on boxing and unboxing, see <hyperlink>11.3</hyperlink>. </paragraph>
6 </clause>