Home »
.Net
What is boxing and unboxing in C#?
Learn: What is boxing and unboxing in C#.Net with definitions, declaration and Example?
There are 2 types in c# one is value type and other is reference type. Object is the base class of all the types in C#.
When a value type is converted into object type then this implicitly conversion process is called boxing. On the other hand when an object type is converted back to its value type explicitly then it is called as unboxing.
Example:
int a = 10;
// Here value of variable a is boxed and assigned into variable o;
object o = a;
The value of object o need to be unboxed at time of retrieval.
int a =(int)o;
An explicit conversion is required while unboxing process.