title: C# IComparer custom sort list using child count with different condition
body: <p>I want to sort C# list using custom comparer.
  I have list of TreeNodes and I want to sort them using count of child nodes
  (TreeNode.GetNodeCount(true)), but nodes with &lt;=2 node count should be put at end.
  Using code below, it sometimes works, but sometimes I get exception that comparer is wrong because comparer output is wrong.</p>
  
  <p>My current code is:</p>
  
  <pre><code>public class XPathComparer : IComparer&lt;TreeNode&gt;
  {
      public int Compare(TreeNode x, TreeNode y)
      {
          if ( 
              (x != null &amp;&amp; x.GetNodeCount(true) &lt;= 2) || 
              (y != null &amp;&amp; y.GetNodeCount(true) &lt;= 2) 
              )
              return -1;
          return x.GetNodeCount(true).CompareTo(y.GetNodeCount(true));
      }
  }
  </code></pre>