Users Pricing

articles

home / developersection / articles / value type and boxing

Value Type and Boxing

Anonymous User 4997 17 Jul 2010 Updated 04 Mar 2020

The operation of converting value type to reference type is called Boxing and the

reverse operation is called Unboxing.

Boxing

int Val = 1; //Value type

            Object Obj = Val; //Boxing

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. This is

called Boxing

Unboxing

            int i = (int)Obj;  //Unboxing

Here we are converting a value of a Reference Type into a value of a Value Type. This

is called Unboxing.

Now, displaying the value of i.

MessageBox.Show("The value is   : " + i);

 

 Value Type and Boxing


I am a content writter !


1 Comments