BOXING AND UNBOXING
• Boxing and Unboxing enable value types to be treated as objects
• Boxing a value type packages it inside an instance of the Object reference type
• This allows the value type to be stored on the garbage collected heap
• Unboxing extracts the value type from an object
EXAMPLE OF BOXING
int i = 123;
object o = (object) i ;
EXAMPLE OF UNBOXING
object o;
o = 123;
i = (int)o;
No comments:
Post a Comment