Saturday 5 November 2016

Boxing Vs UnBoxing

Boxing


 The operation of Converting a Value Type to a Reference Type is called Boxing and the reverse operation is called Unboxing.

 
The first line we created a Value Type Val and assigned a value to Val. The second line , we created an instance of Object Obj and assign the value of Val to Obj. From the above operation (Object Obj = i ) we saw converting a value of a Value Type into a value of a corresponding Reference Type . These types of operation is called Boxing.

UnBoxing


 

The first two line shows how to Box a Value Type . The next line (int i = (int) Obj) shows extracts the Value Type from the Object . That is converting a value of a Reference Type into a value of a Value Type. This operation is called UnBoxing.







Hope this information  helpful to you. Thank you for taking time to look at my blog. ----- Syed Sadiq Ali.   



   



No comments: