8.26.2012

Difference between Boxing and Unboxing in C#

Difference between Boxing and Unboxing in C#
S.No Boxing Unboxing
1
Meaning:
Boxing is the process of converting a value type to the reference type.
Meaning:
Unboxing is the process of converting a reference type to value type.
2
Type of Conversion:
Implicit Conversion
Type of Conversion:
Explicit Conversion
3
Example:
int i = 1;
object obj = i; //boxing
Example:
object obj = 123;
i = (int)obj ; // unboxing

2 comments: