The generics IComparable<T>

T

TonyJ

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
 
J

Jon Skeet [C# MVP]

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?

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
 
M

Marc Gravell

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
 
P

Peter Sestoft

TonyJ said:
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top