title: C# List.Sort doesn't sort
body: <p>I have a <code>List&lt;T&gt;</code> I want to sort, so I used <code>List&lt;T&gt;.Sort(Comparison&lt;T&gt;)</code>. My code didn't work as expected and after some debugging I found that while the order of the items contained within did indeed change, it didn't become sorted.<br>
  The code is here:</p>
  
  <pre><code>System.Comparison&lt;Intersection&gt; comp=(Intersection one, Intersection other)=&gt;{//Sort sorts from lowest to highest
      if(one.index&gt;other.index){
          return 1;
      }
      else if(one.index&lt;other.index){
          return -1;
      }
      else if((one.point-one.node.position).sqrMagnitude&gt;(other.point-other.node.position).sqrMagnitude){
          return 1;
      }
      else{
          return -1;
      }
  };
  intersections.Sort(comp);
  </code></pre>
  
  <p>Trouble is, after the sort the items can be found in order such that the third item has index 7 while the fourth has 6. I thought that there might be something wrong with the comparison lambda, but I added a code which used the same function to compare sequential items, but it behaved correctly and sometimes returned 1,  so the problem is clearly elsewhere.<br>
  The afterward comparison:</p>
  
  <pre><code>for(int he=1; he&lt;intersections.Count; he++){
      Debug.Log(comp(intersections[he-1], intersections[he]));
  }
  </code></pre>
  
  <p>Is there something I'm missing or is my <code>List&lt;T&gt;.Sort</code> implementation faulty and I should just make my own sorting method?</p>
  
  <p>The structure looks like this:</p>
  
  <pre><code>class Intersection{
      public PolyNode node;
      public int index;
      public Polygon poly;
      public Intersection sister;
      public bool is_out;
      public sbyte wallnum;
      public Vector2 point;
      public int list_index;
  }
  </code></pre>