Solved

IComparer or IComparable interfaces...

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now