public class Foo : IComparable<Foo> { public Foo() { } public int Value { get; set; } public int CompareTo(Foo other) { if (other == null) { return 1; } return this.Value.CompareTo(other.Value); } }
The trick is the line, which checks for the null comparison. Since null is always less than this, the method must return a value greater than zero (0).
Also see the remarks in the documentation:
Greater than zero: This object is greater than other. ... By definition, any object compares greater than null (Nothing in Visual Basic), and two null references compare equal to each other.