Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IComparer or IComparable interfaces...

Posted on 2004-10-15
2
Medium Priority
?
997 Views
Last Modified: 2009-07-29
I don't understand when one should implement the IComparer or IComparable interface or really the difference between the two? They both return int's based on whether one is greater, equal or less than the other.
0
Comment
Question by:dotnet22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 1600 total points
ID: 12321633
0
 
LVL 4

Assisted Solution

by:Farshid-Zaker
Farshid-Zaker earned 400 total points
ID: 12321685
hi dotnet22,
When you implement IComparable interface in a class, objects of it got the ability to compare themselves to any other object of the same class. That is a generic interface:
myObject.CompareTo(otherObject);

Classes that have implemented IComparer, just can compare any two other objects and return the result. They are not stateful objects and just COMPARE! IComparer objects are mostly used in Array.Sort or Array.BinarySearch methods as the last parameter.
There are 3 classes which has implemented it and ready for use in dotnet framework, the most famous one is Comparer. The two others are CaseInsensitiveComparer and KeysConverter.

Thanks,
Farshid
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question