Defines a method that a type implements to compare two objects.

See Also: IComparer<T> Members


public interface IComparer<T>

Type Parameters

Documentation for this section has not yet been entered.


This interface is used with the erload:System.Collections.Generic.List`1.Sort and erload:System.Collections.Generic.List`1.BinarySearch methods. It provides a way to customize the sort order of a collection. Classes that implement this interface include the SortedDictionary`2 and SortedList`2 generic classes.

The default implementation of this interface is the Comparer`1 class. The StringComparer class implements this interface for type string.

This interface supports ordering comparisons. That is, when the Comparer`1.Compare(`0, `0) method returns 0, it means that two objects sort the same. Implementation of exact equality comparisons is provided by the IEqualityComparer`1 generic interface.

We recommend that you derive from the Comparer`1 class instead of implementing the IComparer`1 interface, because the Comparer`1 class provides an explicit interface implementation of the Comparer`1.System#Collections#IComparer#Compare(object, object) method and the Comparer`1.Default property that gets the default comparer for the object.


Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions:,
Since: .NET 2.0