title: .NET boxing / unboxing vs casting performance
body: <p>I'm trying to understand which of two solutions are preferred from a performance perspective.
  For example, I have two pieces of code:  </p>
  
  <p>1) Boxing / Unboxing</p>
  
  <pre><code>int val = 5;
  Session["key"] = val; 
  int val2 = (int)Session["key"];
  </code></pre>
  
  <p>2) Casting (IntObj has int Value property to store int)</p>
  
  <pre><code>IntObj val = new IntObj(5);  
  Session["key"] = val;
  int val2 = ((IntObj )Session["key"]).Value;
  </code></pre>
  
  <p>What is the memory management difference between these examples?
  Is there a faster way to perform such operations?</p>
  
  <p><strong>NOTE:</strong> <code>Session</code> is just for example, it can be any <code>Dictionary&lt;string, object&gt;</code></p>