title: Array boundaries check optimization in a for-loop
body: <pre><code>        var ar = new int[500000000];
  
          var sw = new Stopwatch();
          sw.Start();
  
          var length = ar.Length;
          for (var i = 0; i &lt; length; i++)
          {
              if (ar[i] == 0);
          }
  
          sw.Stop();
  </code></pre>
  
  <p>sw.ElapsedMilliseconds: ~2930ms</p>
  
  <pre><code>        var ar = new int[500000000];
  
          var sw = new Stopwatch();
          sw.Start();
  
          for (var i = 0; i &lt; ar.Length; i++)
          {
              if (ar[i] == 0);
          }
  
          sw.Stop();
  </code></pre>
  
  <p>sw.ElapsedMilliseconds: ~3520ms</p>
  
  <p>Win8x64, VS12, .NET4.5, Release build, "Optimize code" on.</p>
  
  <p>As far as I know the second approach should be faster because of an array boundaries check optimization. Am I missing something?</p>