title: Boxing and unboxing with generics
body: <p>The .NET 1.0 way of creating collection of integers (for example) was:</p>
  
  <pre><code>ArrayList list = new ArrayList();
  list.Add(i);          /* boxing   */
  int j = (int)list[0]; /* unboxing */
  </code></pre>
  
  <p>The penalty of using this is the lack of type safety and performance due to boxing and unboxing.</p>
  
  <p>The .NET 2.0 way is to use generics:</p>
  
  <pre><code>List&lt;int&gt; list = new List&lt;int&gt;();
  list.Add(i);
  int j = list[0];
  </code></pre>
  
  <p>The price of boxing (to my understanding) is the need to create an object on the heap, copy the stack allocated integer to the new object and vice-versa for unboxing.</p>
  
  <p>How does the use of generics overcome this? Does the stack-allocated integer stays on the stack and being pointed to from the heap (I guess this is not the case because of what will happen when it will get out of scope)? It seems like there is still a need of copying it somewhere else out of the stack.</p>
  
  <p>What is really going on?</p>