IComparer<(Of <(T>)>) Interface

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)


Public Interface IComparer(Of In T)
public interface IComparer<in T>

Type Parameters

  • inInininT
    The type of objects to compare.

    This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived. For more information about covariance and contravariance, see [2678dc63-c7f9-4590-9ddc-0a4df684d42e].

The IComparer<(Of <(T>)>) type exposes the following members.


Name Description
Compare Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.



This interface is used with the List<(Of <(T>)>)..::.Sort and List<(Of <(T>)>)..::.BinarySearch methods. It provides a way to customize the sort order of a collection.

The default implementation of this interface is the Comparer<(Of <(T>)>) class. The StringComparer class implements this interface for type String.

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

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


System.Collections.Generic Namespace

Comparer<(Of <(T>)>)





IEqualityComparer<(Of <(T>)>)