Home > DeveloperSection > Articles > Value Type and Boxing

Value Type and Boxing

.NET C#  .NET 
1 Comment(s)
 3069  View(s)
Rate this:

Value Type and Boxing in C#.Net

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


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


            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);


By Sunil Singh on   one month ago

Your words increase my knowledge for sure. Thanks

Don't want to miss updates? Please click the below button!

Follow MindStick