What is boxing and unboxing?

Questions by vHarish_06

Showing Answers 1 - 28 of 28 Answers

Sameer P.

  • Oct 15th, 2007
 

Boxing is converting a value type to reference type

Unboxing is an explicit operation.

Eg.

In C# :

int X=1;
Object Y;
int Z;

Y=X; -------------> This is BOXING
Z=(int)Y; ----------------> This is UNBOXING

sudhakar

  • Oct 16th, 2007
 

Boxing:    Boxing is process of converting valueType variable to Referance Type veriable at runtime.
Unboxing:    Unboxing is a process of converting referance type to value type variable at run time.

  Was this answer useful?  Yes

Gavaskar.s

  • Nov 16th, 2007
 

Boxing: An value type will be convertered into object type.


Unboxing: Object type will be convertered into value type.

parii

  • Dec 10th, 2007
 

Boxing is what happens when a value-type object is assigned to a reference-type variable.
Unboxing is what happens when a reference-type variable is assigned to a value-type variable.

arshad236

  • Jan 16th, 2008
 

Boxing is a process of converting value type into reference type while unboxing is vice versa

What happened in backend.

Value type is stored in Stacks
Reference type is stored in Heap

So boxing.

Values shifted Stacks to Heap and vice versa.

  Was this answer useful?  Yes

kirangiet

  • Oct 23rd, 2009
 

Boxing: Converting Value Type into Reference Type

Example:
 
int i = 10;

string str = Convert.ToString(i);


Unboxing: Converting Reference Type into Value Type

Example:

string str = "10";

int i = Convert.ToInt16(str) ;

Boxing: Boxing is process of converting valueType variable to Reference Type variable at runtime.
Unboxing: Unboxing is a process of converting reference type to value type variable at run time.
 Value type is stored in Stacks
Reference type is stored in Heap
In C# : 

int X=1;
Object Y;
int Z;

Y=X; -------------> This is BOXING
Z=(int)Y; ----------------> This is UNBOXING

Js

  • Sep 12th, 2011
 

Boxing

Value Type -----> Reference Type

Un Boxing

Reference Type ------> Value Type

  Was this answer useful?  Yes

Boxing permits any value type to be implicitly converted to type object or to any interface type implemented by value type.
Unboxing is vice verse of boxing operation where the value is copied from the instance into appropriate storage location.

EX:-
Dim X As Integer
Dim Y As Object

X=10<--BOXING PROCESS-->
Y=X<--UNBOXING PROCESS-->

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions