What is boxing and unboxing?

Boxing: Converting a value type to an object (reference type).

  • Implicit conversion.

Unboxing: Converting an object back to a value type.

  • Explicit conversion.

Example:

int i = 123;
object obj = i; // Boxing
int j = (int)obj; // Unboxing

Leave a Reply

Your email address will not be published. Required fields are marked *