What is boxing?

Q

What is boxing?

✍: Guest

A

Boxing is an implicit conversion of a value type to the type object
int i = 123; // A value type
Object box = i // Boxing
Unboxing is an explicit conversion from the type object to a value type
int i = 123; // A value type object box = i; // Boxing
int j = (int)box; // Unboxing

2014-02-27, 1613👍, 0💬