Overview
- Boxing is an implicit conversion of a value type to the object type.
- Boxing a value type will copy the value to the heap, and place a reference to the boxed value on the stack.
Good practice
- Try to avoid boxing/unboxing when possible; use generics or multiple overloads instead.
- Read Boxing/Unboxing In .NET for performance tests.
Examples
Boxing Operation
int i = 123;
object o = (object)i;
Unboxing Operation
object o = 123;
int i = (int)o;
You May Also Like

Exam 70-536 Study Notes
My study notes for Microsoft exam 70-536: .NET types, collections, generics, I/O, serialization and more, with C# examples.

Starting Exam 70-536 Study
After a burnout, I'm putting my own project on hold to study for Microsoft exam 70-536.

Design Patterns - Proxy Pattern
The Proxy Pattern, and the last article in the design patterns series, now that I've finished reading Head First Design Patterns.




