title: Why is code behavior different in release & debug mode?
body: <p>Consider the following code:</p>
  
  <pre><code>private static void Main(string[] args)
  {
      var ar = new double[]
      {
          100
      };
  
      FillTo(ref ar, 5);
      Console.WriteLine(string.Join(",", ar.Select(a =&gt; a.ToString()).ToArray()));
  }
  
  public static void FillTo(ref double[] dd, int N)
  {
      if (dd.Length &gt;= N)
          return;
  
      double[] Old = dd;
      double d = double.NaN;
      if (Old.Length &gt; 0)
          d = Old[0];
  
      dd = new double[N];
  
      for (int i = 0; i &lt; Old.Length; i++)
      {
          dd[N - Old.Length + i] = Old[i];
      }
      for (int i = 0; i &lt; N - Old.Length; i++)
          dd[i] = d;
  }
  </code></pre>
  
  <p>The result in Debug mode is: 100,100,100,100,100.
  But in Release mode it is: 100,100,100,100,0.</p>
  
  <p>What is happening?</p>
  
  <p>It was tested using .NET framework 4.7.1 and .NET Core 2.0.0.</p>