Box and unbox in C#
describe box and unbox with example how it is stored in heap and stack.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jul 19, 2012, 6:43 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 19, 2012, 7:46 PM EDT
Hi,
Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. Boxing is used to store value types in the garbage-collected heap. Boxing is an implicit conversion of a value type to the type object or to any interface type implemented by this value type.
Unboxing is an explicit conversion from the type object to a value type or from an interface type to a value type that implements the interface.
int temp1 = 999; // a value type
object tempObj = i; // boxing
int temp2 = (int)tempObj; // unboxing
please refer
http://www.codeproject.com/Articles/2225/Boxing-and-unboxing-in-C
http://www.csharphelp.com/2006/02/boxing-and-unboxing-c/
hope this will help you.
Prabhu RajaRank #861 · 2.6K reputationPosted Jul 19, 2012, 10:28 PM EDT
http://iamprabhuraja.wordpress.com/?s=boxing+and+unbox