Boxing and unboxing is not to be confused with downcast / upcast.
- Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type.
- When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap.
- Unboxing extracts the value type from the object.
- Boxing is implicit
- Unboxing is explicit.
- The concept of boxing and unboxing underlies the C# view that a value of any type can be treated as an object.
int i = 123; // The following line boxes i. object o = i;
o = 123; i = (int)o; // unboxing