fork download
  1. using System;
  2. using System.Globalization;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public abstract class Parent : IComparable<Parent> {
  8. public string Title;
  9. public Parent(string title){this.Title = title;}
  10.  
  11. public int CompareTo(Parent other){
  12. return this.Title.CompareTo(other.Title);
  13. }
  14. }
  15.  
  16. public class Child : Parent {
  17. public Child() : base("") { }
  18. public Child(string title):base(title){}
  19. }
  20.  
  21.  
  22. public static void Main()
  23. {
  24. List<Child> children = new List<Child>();
  25. children.Add(new Child() { Title = "ABC" });
  26. children.Add(new Child() { Title = "BAB" });
  27. children.Add(new Child() { Title = "ADE" });
  28. children.Sort(); //Fails with "Failed to compare two elements in the array."
  29. foreach(var c in children)
  30. Console.WriteLine(c.Title);
  31. }
  32. }
Runtime error #stdin #stdout 0.03s 36400KB
stdin
Standard input is empty
stdout
Standard output is empty