title: In C#, why does dictionary[0]++ work?
body: <p>Consider the following C# code:</p>
  
  <pre><code>var d = new Dictionary&lt;int, int&gt;();
  d[0] = 0;
  d[0]++;
  </code></pre>
  
  <p>What is the value of d[0] after this code executes? I would expect d[0] == 0, because the Item property of Dictionary&lt;> returns a <strong>value type</strong> <code>int</code>, presumably on the stack, which then gets incremented. Surprisingly, however, when you actually run this code you find d[0] == 1.</p>
  
  <p>The example above behaves as if the indexer is returning a reference type, but now consider the following:</p>
  
  <pre><code>var d = new Dictionary&lt;int, int&gt;();
  d[0] = 0;
  var a = d[0];
  a++;
  </code></pre>
  
  <p>What is the value of d[0] after this code executes? This time we get d[0] == 0 as expected, so the indexer is definitely not returning a reference.</p>
  
  <p>Does anybody know why we see this behavior?</p>