title: Why does .NET 4.0 sort this array differently than .NET 3.5?
body: <p><a href="https://stackoverflow.com/q/5123659/138757">This stackoverflow question</a> raised an interesting question about sorting double arrays with NaN values. The OP posted the following code:</p>
  
  <pre><code>static void Main(string[] args)
  {
      double[] someArray = { 4.0, 2.0, double.NaN, 1.0, 5.0, 3.0, double.NaN, 10.0, 9.0, 8.0 };
  
      foreach (double db in someArray)
      {
          Console.WriteLine(db);
      }
  
      Array.Sort(someArray);
      Console.WriteLine("\n\n");
      foreach (double db in someArray)
      {
          Console.WriteLine(db);
      }
  
      Console.ReadLine();
  }
  </code></pre>
  
  <p>When you run this under the .NET 3.5 framework, the array is sorted as follows:</p>
  
  <p><code>1,4,NaN,2,3,5,8,9,10,NaN</code></p>
  
  <p>When you run it under .NET 4.0, the array is sorted somewhat more logically:</p>
  
  <p><code>NaN,NaN,1,2,3,4,5,8,9,10</code></p>
  
  <p>I can understand why it would sort weirdly in .NET 3.5 (because NaN is not equal to, less than, or greater than, anything). I can also understand why it would sort the way it does in .NET 4.0. My question is, why did this change from 3.5 to 4.0? And where is the Microsoft documentation for this change?</p>