03 July 2014

Boxing vs UnBoxing

Boxing and Unboxing is a  essential concept in .Net’s type system. With Boxing and Unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. The basic differences are :-























 BoxingUnboxing
Definition:Boxing is the process of converting a value type to the reference type.Unboxing is the process of converting a reference type to value type

.
Type of Conversion:Implicit ConversionExplicit Conversion

 
Example:int i = 221;

object obj = i; //boxing
object obj = 213;

i = (int)obj ; // unboxing

 

No comments: