当使用IComparable的&LT; T&GT;比。的IComparer&LT; T&GT; [英] When to use IComparable<T> Vs. IComparer<T>
问题描述
我试图找出这些接口,我需要实现的。他们都基本上做同样的事情。我什么时候会用一个比其他?
那么,他们都没有的非常的同样的事情, 我倾向于使用 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? Well they are not quite the same thing as I tend to use 这篇关于当使用IComparable的&LT; T&GT;比。的IComparer&LT; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!的IComparer&LT; T&GT;
T&GT; 的是,其能够将自己与相同类型的其他实例比较类型实施<上的类型,其能够比较两个不同的物体,同时 IComparable的&所述实施/ P>
IComparable的&LT; T&GT;
的时候,我需要知道如何另一个实例涉及到这
实例。 的IComparer&LT; T&GT;
是分类收集有用的的IComparer&LT; T&GT;
表示比较之外IComparer<T>
is implemented on a type that is capable of comparing two different objects while IComparable<T>
is implemented on types that are able to compare themselves with other instances of the same type.IComparable<T>
for times when I need to know how another instance relates to this
instance. IComparer<T>
is useful for sorting collections as the IComparer<T>
stands outside of the comparison.