When to use IComparable Vs. IComparer

前端 未结 8 1273
[愿得一人]
[愿得一人] 2020-11-29 16:07

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?

8条回答
  •  萌比男神i
    2020-11-29 16:36

    Use IComparable when the class has an intrinsic comparison.

    Use IComparer when you want a comparison method other than the class' intrinsic comparison, if it has one.

提交回复
热议问题