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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Prabhu RajaPosted Jul 20, 2012, 2:28 AM
http://iamprabhuraja.wordpress.com/?s=boxing+and+unbox
Jignesh TrivediPosted Jul 19, 2012, 11:46 PM
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.
VulpesPosted Jul 19, 2012, 10:43 AM