EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

IComparer<T> Interface

April 12, 2014

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

Namespace:  System.Collections.Generic
Assembly:  mscorlib (in mscorlib.dll)
public interface IComparer<in T>

Type Parameters

in T

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<T> type exposes the following members.

  NameDescription
Public methodCompareCompares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
Top

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

The default implementation of this interface is the Comparer<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<T> generic interface.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Cela vous a-t-il été utile ?
(1500 caractères restants)
Merci pour vos suggestions.
Afficher:
© 2014 Microsoft. Tous droits réservés.