What is Boxing and Unboxing?
Answer Posted / 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 |
Post New Answer View All Answers
How are sessions stored?
What is the full meaning of asp.net?
List the advantages and disadvantages of user control an custom control?
What is the Intermittent crashing of application in production?
What is asp.net used for?
What is aspect-oriented programming?
What are the asp.net security controls?
Explain the significance of routing? : asp.net mvc
Describe Segmentation With Paging?
Why we use asp.net for website development?
What is a form tag?
What are the different properties of server control that exists?
What are the disadvantages of using session?
What is the size of Get method and how much data it can store?
What are the security types in asp.net?