What is Boxing and Unboxing?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
You are using the try? catch block seen in the following code segment, but no exceptions are ever caught by the catch block. What is the problem? SqlConnection cn =new sqlConnection(strSQL); SqlDataSet ds; try { cn.open(); //perform the data processing steps ??.. } catch (OleDbException e) { ?.. } a) The exception class is wrong; it should be sqlErrors. b) The exception class is wrong; it should be sqlSyntaxExceptios. c) The exception class is wrong; it should be sqlExceptions. d) The exception class is wrong; it should be sqlExcptions.
2 Answers Microsoft, Syntax Softtech,
Where is the view state data stored?
What is the good practice to implement validations in aspx page?
Do gac'ed assemblies have fulltrust?
What are the ways to show data grid inside a data grid for a master details type of tables? If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?
How do we ensure view state has not tampered?
What is the used of "ispostback" property?
Name some asp objects?
What is Serilazation? how many type of serilazation are their?
When we use cookie less session? Explain its working?
0 Answers Sans Pareil IT Services,
What is the difference between globalization and localization?
How can we prevent an aspx page get refreshed when any information fetch from the database ?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)