Wednesday, 11 March 2020

Boxing and Unboxing

Boxing and Unboxing
Value types (int, struct, enum) are also compatible with the object!
Boxing
The assignment
Object obj = 3;
wraps up the value 3 into a heap object

Unboxing
The assignment
int x = (int) obj;
unwraps the value again

Eg:- 
int x=123;
 Object O=123; //boxing
Int y=(int)O; //Unboxing

https://www.youtube.com/channel/UCKLRUr6U5OFeu7FLOpQ-FSw/videos

0 comments

Post a Comment