Solved

IComparer or IComparable interfaces...

Posted on 2004-10-15
2
975 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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