Hi,
Ques What is the Boxing and Unboxing in the .Net ?
Boxing and Unboxing in the .Net
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
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
Sam HobbsRank #107 · 20.5K reputationPosted Mar 28, 2012, 6:51 PM EDT
SenthilkumarRank #387 · 6.5K reputationPosted Mar 28, 2012, 7:39 PM EDT
Boxing is converting an value type into object. The unboxing is converting an object type into value type.
There are two types in C#.
1) Reference Types
2) Value Types
Reference type is nothing but object type which is stored in the heap memory. The object will be cleared automatically from the memory when an object is no longer needed.
The value type is stored in the stack memory.
In C# the boxing happens implicitly.
For example
int i =10;
object obj = i; //Implicit type casting
Here the value type will be directly assigned to the object type.
If you want to convert an object type into value type
object obj = 10;
int i = (int) obj; //type casting (unboxing)
If you want to more infor then,
http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx