[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Boxes a value type.
Assembly: mscorlib (in mscorlib.dll)
Boxing a value type creates an object and performs a shallow copy of the fields of the specified value type into the new object.
This method allows a value class to be manipulated as an object while it retains the aliasing behavior of a value class.
The return value depends on whether the value class is mutable or immutable:
If the value being assigned is a mutable value class, the method returns a shallow copy of the class, because value classes have copy semantics.
If the value being assigned is an immutable value class, the method returns the object itself, instead of a copy of the class.
Compilers of dynamically typed languages can use this method to make sure that boxed value types work identically to unboxed value types. That is, boxed value types get cloned when you pass them around, and they are always passed by value. The compiler can call to assign a value type to an object or to pass a value type as a parameter of a type object.
This method is used by compilers.
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.