Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

The generics IComparable<T>

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TonyJ - 12 Feb 2008 09:42 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.