Standing on the shoulders of giants. RSS 2.0
# Monday, September 15, 2008
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.

Monday, September 15, 2008 8:55:47 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [0] - Trackback
Codesnippet
Comments are closed.
Ads
About
© Copyright 2012
Paul van Brenk
Sign In
newtelligence dasBlog 2.3.2011.0
All Content © 2012, Paul van Brenk
DasBlog theme 'Business' created by Christoph De Baene (delarou)