Hello!
I'm reading in a book from Microsoft that the generic interface
IComparabler<T> define 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<T> but
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] - 12 Feb 2008 09:48 GMT
> I'm reading in a book from Microsoft that the generic interface
> IComparabler<T> define the two methods
[quoted text clipped - 6 lines]
> Is this just a bad book telling me wrong thing?
> Or do I misunderstand it in some way?
Do you mean IComparer<T> or 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<T> and IEqualityComparer<T>.
Jon
Marc Gravell - 12 Feb 2008 09:51 GMT
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
Marc Gravell - 12 Feb 2008 09:53 GMT
Frther; there is a "bool Equals(T other)", but that is on
IEquatable<T>
Marc
Peter Sestoft - 17 Feb 2008 15:03 GMT
> I'm reading in a book from Microsoft that the generic interface
> IComparabler<T> define the two methods
[quoted text clipped - 3 lines]
> in the IComparabler<T> but
> the Equals is not mentioned.
An early design for the .NET 2.0 class library had Equals(T) on
IComparable<T>, but fortunately this was changed before release.
The book may have been written against that early design.
Peter

Signature
IT University of Copenhagen * sestoft@itu.dk * www.itu.dk/people/sestoft
Rued Langgaards Vej 7, DK-2300 Copenhagen S, Denmark * Tel +45 72 18 50 83