I’m trying to figure out which of these interfaces I need to implement. They both essentially do the same thing. When would I use one over the other?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well they are not quite the same thing as
IComparer<T>is implemented on a type that is capable of comparing two different objects whileIComparable<T>is implemented on types that are able to compare themselves with other instances of the same type.I tend to use
IComparable<T>for times when I need to know how another instance relates tothisinstance.IComparer<T>is useful for sorting collections as theIComparer<T>stands outside of the comparison.