boxing means converting value type to reference type and
unboxing means converting reference type to value type.why
we need boxing and unboxing?
Answers were Sorted based on User's Feedback
Answer / uday
We use boxing and un-boxing when we assign a value to an
object and vice-versa.
Ex:
Int i=10;
Object o=i //this is boxing
int j=(int)o; //this is unboxing
When u say boxing, an object box is allocated and then the
value is copied to that box.
When u unbox, the value is copied out of the object box and
copied into storage location.
| Is This Answer Correct ? | 13 Yes | 2 No |
Answer / madhu maaydi
some times super class ref is may not available to subclass objects at that time we may go for umboxing, data in the web application travers in the net throuw objects only but not through variables at that time we need to type cast it into equalent obecjt at this time we go for boxing and auto boximg....
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / deepak
actually we need boxing and unboxing to keep more than one type of value type of variables in a common reference type of collection.. so that you can do the common operation in a loop or anywhere else.. by unboxing one by one.. also you can pass that collection to any method.. so you dont need to make many overloaded method for every type of value type..
| Is This Answer Correct ? | 0 Yes | 1 No |
What is windows forms in c#?
How can you sort the elements of the array in descending order?
1 Answers Junosource, Siebel Systems, Wipro,
What is extended class in c#?
Can we declare class as protected?
What is Inheritance in C#?
What are the new features in c# 2.0?
How to raise an selection changed event associated with listbox in datagridview control with a sample example?Here the listbox is a child control associated with datagridview control.
what is default accessibility for a class? what is difference b/w viewstate and controlstate? what is the default access specifier for a top level class which are not nested into other classes?
Explain nullable types in c#?
What is the use of main method in c#?
What is use of hashtable in c#?
How are Windows programs different from normal C-programs?
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)