Social Icons

Friday, 19 July 2013

Boxing and UnBoxing in .Net Interview Question

Introduction:

 One of the must and should question in interviews is What is Boxing and UnBoxing.
  
                   UnIntentionally while coding we will use this process many times. Let us explore this simple process.

What is Boxing:

 It is the process of converting a value type into reference type. i..e Let us have a variable num which has value 100. It is a value type, now if we want to convert this to reference type i.e object type then this process is called as Boxing.

            int num=100;
            object obj=num;

One thing we should remember here is object is the base type of all data types in .net.

What is UnBoxing:

It is exactly reverse of Boxing, i.e Converting a reference type  back to value type is called UnBoxing. But here explicit type casting require.

            int num=Convert.Int32(obj);



No comments:

Post a comment

Please Give your Valuable Suggestions,Questions and Comments to improve my blog.