Monday, October 29, 2012

Boxing and Unboxing in C#

Boxing is the process of converting value type to the object type or to any interface type implemented by this value type. Whenever there is boxing the values are in the System.Object and the value is stored on the heap.

int i = 123;
object o = i; //boxing
 
Unboxing is the process where the value type is extracted from object.
 
o = 123;
i = (int)o; //unboxing

 
  

No comments:

Post a Comment