title: Why does List<T>.Sort() where T:IComparable<T> produce a different order than List<T>.Sort(IComparer<T>)?
body: <p><code>List&lt;T&gt;.Sort()</code> where <code>T:IComparable&lt;T&gt;</code> produces a different order than <code>List&lt;T&gt;.Sort(IComparer&lt;T&gt;)</code>, with equal inputs.</p>
  <p><strong>Note the comparer is not really correct - it does not return 0 for equality.</strong></p>
  <p>Both orders are valid (because the difference lies in the equal elements), but I'm wondering where the difference arises from, having looked through the source, and if it is possible to alter the IComparable.CompareTo to match the behavior of the IComparer.Compare when passed into the list.</p>
  <p>The reason I'm looking at this is because IComparable is far faster than using an IComparer (which I'm guessing is why there are two different implementations in .NET), and I was hoping to improve the performance of an open source library by switching the IComparer to IComparable.</p>
  <p>A full example is at: <a href="https://dotnetfiddle.net/b7s6my" rel="nofollow noreferrer">https://dotnetfiddle.net/b7s6my</a></p>
  <p>Here's the class/comparer:</p>
  <pre><code>public class Point : IComparable&lt;Point&gt;
  {
     public int X { get; }
     public int Y { get; }
     public int UID { get; set; } //Set by outside code
      
     public Point(int x, int y)
     {
        X = x;
        Y = y;
     }
      
     public int CompareTo(Point b)
     {
        return PointComparer.Default.Compare(this, b);
     }
  }
  public class PointComparer : IComparer&lt;Point&gt;
  {
     public readonly static PointComparer Default = new PointComparer();
                  
     public int Compare(Point a, Point b)
     {
         if (a.Y == b.Y)
         {
            return (a.X &lt; b.X) ? -1 : 1;
         }
         return (a.Y &gt; b.Y) ? -1 : 1;
     }
  }
  </code></pre>
  <p>Note the comparer is not mine (so I can't really change it) - and changing the sort order causes the surrounding code to fail.</p>