title: Custom class: Failed to compare two elements in the array
body: <p>I have a list of abstract Class elements and when I try to sort it I get an exception with a message "Failed to compare two elements in the array"</p>
  
  <p>Abstract Class:</p>
  
  <pre><code>public abstract class Node : IComparable&lt;Leaf&gt;, IComparable&lt;Interrior&gt;
  {
      public virtual ulong Weight { get; set; }
      protected virtual int CompareWeights(Node node)
      {
          if (this.Weight &lt; node.Weight) return -1;
          else if (this.Weight &gt; node.Weight) return 1;
          else return 0;
      }
      public abstract int CompareTo(Interrior node);
      public abstract int CompareTo(Leaf node);
  }
  </code></pre>
  
  <p>Derived classes:</p>
  
  <pre><code>public class Interrior : Node
  {
      public Interrior(byte age, Node left, Node right)
      {
          Age = age;
          Left = left;
          Right = right;
          Weight = Left.Weight + Right.Weight;
      }
      public byte Age { get; }
      public Node Left { get; }
      public Node Right { get; }
      public override int CompareTo(Interrior node)
      {
          var result = CompareWeights(node);
          if (result == 0) result = this.Age &lt; node.Age ? -1 : 1;
          return result;
      }
      public override int CompareTo(Leaf node)
      {
          var result = CompareWeights(node);
          if (result == 0) result = 1;
          return result;
      }
  }
  public class Leaf : Node
  {
      public Leaf(byte symbol)
      {
          Symbol = symbol;
          Weight = 1;
      }
      public byte Symbol { get; }
      public override int CompareTo(Interrior node)
      {
          var result = CompareWeights(node);
          if (result == 0) result = -1;
          return result;
      }
  
      public override int CompareTo(Leaf node)
      {
          var result = CompareWeights(node);
          if (result == 0) result = this.Symbol &lt; node.Symbol ? -1 : 1;
          return result;
      }
  }
  </code></pre>
  
  <p>Can anybody please tell me what I'm doing wrong here? I want to create List of nodes and call a method sort on it, thank you.</p>