• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 586
  • Last Modified:

Boxing and Unboxing - C# / VB.NET ?

Hi,

What will happen when there is Boxing occurs ? And when there is Unboxing occurs ?

Means:

Boxing: Stack value is written to Heap ???

Unboxing: Heap value is written to Stack ???

Please do let me know how that works with respect to memory allocations.

Thanks
0
milani_lucie
Asked:
milani_lucie
  • 2
2 Solutions
 
AndyAinscowCommented:
I think you have said it pretty much correctly (or at least how I understand it).  

Boxing will convert a value type into a reference type (for garbage collection heap) and the unboxing releases a reference type into the value type of object.
0
 
anarki_jimbelCommented:
Yes, it happens exactly as you described:
Boxing converts value type to reference type , thus allocating memory on Heap . Unboxing converts already boxed reference types to value types through explicit casting , thus allocating memory on stack .
And one more reference:
http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now