The generics IComparable<T>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TonyJ

    #1

    The generics IComparable<T>

    Hello!

    I'm reading in a book from Microsoft that the generic interface
    IComparabler<Td efine the two methods
    CompareTo and Equals.

    Now to my querstion if I look in the docs it says that CompareTo is defined
    in the IComparabler<Tb ut
    the Equals is not mentioned.

    Is this just a bad book telling me wrong thing?
    Or do I misunderstand it in some way?

    //Tony


  • Jon Skeet [C# MVP]

    #2
    Re: The generics IComparable&lt; T&gt;

    On Feb 12, 9:45 am, "TonyJ" <johansson.ande rs...@telia.com wrote:
    I'm reading in a book from Microsoft that the generic interface
    IComparabler<Td efine the two methods
    CompareTo and Equals.
    >
    Now to my querstion if I look in the docs it says that CompareTo is defined
    in the IComparabler<Tb ut
    the Equals is not mentioned.
    >
    Is this just a bad book telling me wrong thing?
    Or do I misunderstand it in some way?
    Do you mean IComparer<Tor IComparable<T>? They are two different
    interfaces, but there's no such thing as IComparabler<T> .

    In either case though, there's no Equals method. That appears in
    IEquatable<Tand IEqualityCompar er<T>.

    Jon

    Comment

    • Marc Gravell

      #3
      Re: The generics IComparable&lt; T&gt;

      The book is wrong (or is being taken out of context; hard to tell
      without a citation); it inherits a few methods from object (Equals(),
      GetHashCode(), GetType() and ToString() ) but the interface itself
      only declares CompareTo().

      Marc


      Comment

      • Marc Gravell

        #4
        Re: The generics IComparable&lt; T&gt;

        Frther; there is a "bool Equals(T other)", but that is on
        IEquatable<T>

        Marc


        Comment

        Working...