title: Why is setting a field many times slower than getting a field?
body: <p>I already knew that setting a field is much slower than setting a local variable, but it also appears that setting a field <strong>with</strong> a local variable is much slower than setting a local variable with a field. Why is this? In either case the address of the field is used.</p>
  
  <pre><code>public class Test
  {
      public int A = 0;
      public int B = 4;
  
      public void Method1() // Set local with field
      {
          int a = A;
  
          for (int i = 0; i &lt; 100; i++)
          {
              a += B;
          }
  
          A = a;
      }
  
      public void Method2() // Set field with local
      {
          int b = B;
  
          for (int i = 0; i &lt; 100; i++)
          {
              A += b;
          }
      }
  }
  </code></pre>
  
  <p>The benchmark results with 10e+6 iterations are:</p>
  
  <pre>
  Method1: 28.1321 ms
  Method2: 162.4528 ms
  </pre>