Pages

Friday 24 May 2013

Difference between Boxing and Unboxing in C# with an Example

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.
Boxing
Unboxing
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 Conversion
Explicit Conversion
Example:
int i = 221;
object obj = i; //boxing
object obj = 213;
i = (int)obj ; // unboxing

1 comment: