What is Boxing and Unboxing?

Answers were Sorted based on User's Feedback



What is Boxing and Unboxing?..

Answer / kautilya

Boxing is to implicitly converting value type to refrence
type,

int x = 10;
double y = x;


Unboxing is to explicitly converting refrence type to value
type

double y = 10.234;
int x = (int)y;

Is This Answer Correct ?    8 Yes 1 No

What is Boxing and Unboxing?..

Answer / lakshmi

The conversion of the value type to reference type is known
as Boxing and converting reference type back to value type
is known as Unboxing.

Is This Answer Correct ?    8 Yes 1 No

What is Boxing and Unboxing?..

Answer / kumaresh

BOXING: Converting value type to referenc type.
Here we go with an example,

ArrayList instance = new ArrayList()
//In the above line of code,ArrayList is a reference
type.Add some items to the arraylist. For example,

instance.Add(1);
instance.Add(100);
instance.Add(3);
//3 items added to the arraylist.
//Integer valuee 3 is value type.Adding 3 to the reference
type(here it's arraylist) is boxing.
i.e., Converting value type to referenc type.

UNBOXING:Converting Reference type to value type.
Below is an example, retrives the items from the
arraylist.

foreach (int item in arrayList)
Console.WriteLine(item);

Here arraylist(referenec type) will have 3 values in the
list, which we added above.
Adding this arraylist items to an int variable[here int
variable is "item"] is unboxing.
i.e.,converting the reference type to value type.

Hope you would have understood.
Thanks

Is This Answer Correct ?    5 Yes 0 No

What is Boxing and Unboxing?..

Answer / eduardo belmonte

Boxing is the process of converting value type to reference
type.

Unboxing is the process of converting from a reference type
to a value type.

Both are slow and should be avoided when possible or
unneeded.

Dim st AS String
Dim obj As Object
Dim n As Integer = 5
st = n ' Boxing happens
obj = n ' Boxing happens

n = st ' Unboxing happens
n = obj ' Unboxing happens

Is This Answer Correct ?    4 Yes 1 No

What is Boxing and Unboxing?..

Answer / amit

The conversion of the value type to reference type is known
as Boxing and converting reference type back to value type
is known as Unboxing.

Is This Answer Correct ?    2 Yes 0 No

What is Boxing and Unboxing?..

Answer / uma

Boxing means converting value type to refrence type and un
boxing means converting refrence type to value type

Is This Answer Correct ?    2 Yes 0 No

What is Boxing and Unboxing?..

Answer / karthik

Boxing:Focing an value type into referencetype is known as boxing.
EX:int a=10;
object obj;
obj=a;
Unboxng:forcing an reference type into value type is known as unboxing.
EX:
int b:
b=(int)obj;
unboxing should be done explicitly using datatype casting.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More ASP.NET Interview Questions

What is latest version of asp.net mvc? : Asp.Net MVC

0 Answers  


What is the concepts of globalization and localization in .net?

0 Answers  


Tell me how asp.net mvc differs from asp.net web forms? : asp.net mvc

0 Answers  


how to update data set?

3 Answers   IBM, TCS,


can I use session variable in App_code Class page??

3 Answers   Wipro,






What is postback and autopostback in asp.net?

0 Answers  


Should user input data validation occur server-side or client-side? Why?

3 Answers   NIC, Siebel Systems,


Why asp.net is better than php?

0 Answers  


how can u display multi language (i.e english,spanish...) web site?

2 Answers  


How you will handle session when deploying application in more than a server? Describe session handling in a webfarm, how does it work and what are the limits?

3 Answers   CoreObjects,


Any body Having SHAREPOINT Material plzzz? please material to send prasad.k12@gmail.com

0 Answers  


Differnce between Control an View State

1 Answers   Proteans,


Categories