Solved

IComparer or IComparable interfaces...

Posted on 2004-10-15
2
983 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 400 total points
ID: 12321633
0
 
LVL 4

Assisted Solution

by:Farshid-Zaker
Farshid-Zaker earned 100 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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