By: Ram Baskar Emailed: 1768 times Printed: 2516 times
Boxing is the operation of converting a value of a value type into a value of a corresponding reference type. Boxing in C# is implicit.
Unboxing is the operation of converting a value of a reference type (previously boxed) into a value of a value type. Unboxing in C# requires an explicit type cast. A boxed object of type T can only be unboxed to a T (or a nullable T).
int foo = 42; // Value type.
object bar = foo; // foo is boxed to bar.
int foo2 = (int)bar; // Unboxed back to value type.
Be the first one to add a comment
Most Viewed Articles (in Csharp )
Most Emailed Articles (in Csharp)