Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What are standard controls?

969


Is there any alternative to avoid name collisions other then Namespaces?

1117


Explain State management in asp.net

1089


Explain parts of assembly?

963


What do you mean by role-based security?

984


What is a proxy in web service?

1073


What does postback mean?

1013


What is asp net theme?

1005


Define the term Scavenging in Caching?

1038


Describe SOA and the tenets of it?

1048


Explain asp.net mvc request life cycle? : asp.net mvc

1069


How can you register a custom server control to a web page?

988


What is a postback url?

877


Do session use cookies in asp net?

1002


Explain the use of view state?

1010