.Net Interview Question: Explain Boxing and Unboxing?

Boxing and unboxing act like bridges between value type and reference types. Converting value type to a reference type is called boxing. Unboxing is casting back an object to its original value type, the value is copied out of the box and into the appropriate storage location.

Below is sample code of boxing and unboxing where integer data type are converted in to object and then casting the object back to integer.

int i = 1;
object obj = i; // boxing
int j = (int) obj; // unboxing