Your CompareTo
function is broken. It doesn't return 0
when an object is compared to itself and it always returns 1
when two objects with valid == false
are compared. So there might be two objectsa
and b
with a.CompareTo(b) == 1
and b.CompareTo(a) == 1
and this might lead to Sort()
behave strangely.
Also, as already noted in the other answer, it should return 1
if other == null
. (shouldn't really matter when the list doesen't contain null
)