ICompareable vs IComparer [modified]
-
Hi All, What are the main differences between these two Interfaces and when we should prefer which one??? and shud we implement these in the same class in which we r comparing or shud we make a new calss for that......also i m having problem implementing IComparer interface when i implement this the compiler gives this error The type or namespace name 'IComparer' could not be found (are you missing a using directive or an assembly reference?) so plz tell me also wots the solution of this Looking forward for help Regards, -- modified at 12:38 Tuesday 23rd May, 2006
-
Hi All, What are the main differences between these two Interfaces and when we should prefer which one??? and shud we implement these in the same class in which we r comparing or shud we make a new calss for that......also i m having problem implementing IComparer interface when i implement this the compiler gives this error The type or namespace name 'IComparer' could not be found (are you missing a using directive or an assembly reference?) so plz tell me also wots the solution of this Looking forward for help Regards, -- modified at 12:38 Tuesday 23rd May, 2006
IComparer is defined in System.Collections. Thus you need to add
using System.Collections;
at the top of your code. IComparable must always be implemented by the the class which should be sorted. IComparer should be implemented in separated classes. You should go with IComparer if you want to sort your objects by different criterias (e.g. by its name, some associated values...). Because IComparer can be separated from the class to be sorted you can have as much implementations as you like. -
Hi All, What are the main differences between these two Interfaces and when we should prefer which one??? and shud we implement these in the same class in which we r comparing or shud we make a new calss for that......also i m having problem implementing IComparer interface when i implement this the compiler gives this error The type or namespace name 'IComparer' could not be found (are you missing a using directive or an assembly reference?) so plz tell me also wots the solution of this Looking forward for help Regards, -- modified at 12:38 Tuesday 23rd May, 2006
IComparer: something that compares other things IComparable: something that get compared
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Islamic Domination: Coming to a Jewish state near you! The apostle Paul, modernly speaking: Epistles of Paul Judah Himango