The __box keyword is used to create a managed object (derived from System::ValueType) from an existing __value class object. When the __box keyword is applied to a __value class:
A managed object is allocated on the common language runtime heap.
The current value of the __value class object is bit-wise copied into the managed object.
The address of the new managed object is returned.
This process is known as boxing. This enables any __value class object to be used in generic routines that work for any managed object because the managed object indirectly inherits from System::Object (since System::ValueType inherits from System::Object).
Note: |
|---|
The newly created boxed object is a copy of the __value class object. Therefore, modifications to the value of the boxed object do not affect the contents of the __value class object.
|