What is Boxing and Unboxing?

by Nithya 2010-01-30 10:10:13

Boxing
Value Types are stored on the stack and Reference types are stored on the heap. The conversion of value type to reference type is known as boxing.

Example:

int i = 123;
object o = (object)i; // boxing


Unboxing
The conversion of reference type back to the value type is known as unboxing.

Example:

o = 123;
i = (int)o; // unboxing

Tagged in:

1016
like
0
dislike
0
mail
flag

You must LOGIN to add comments