Boxing:
It converts a value type (int, char, etc.), to a reference type (object).
Simple terms: To convert a value to an object type.
Boxing is an implicit conversion process.
Here, the value stored on the stack is copied to the object stored on the heap.
Programming example (with a hard-coded value):
Programming Example (using Convert.ToInt32(Console.ReadLine())):
Unboxing:
It converts a reference type (object) back to a value type (int, char, etc.).
Simple terms: To convert an object type back to a value type.
Unboxing is an explicit conversion process.
The object stored on the heap is copied to the value stored on the stack.
Programming Example (with a hard-coded value):
Programming Example (using Convert.ToInt32(Console.ReadLine())):
Top comments (0)