Comparer<T> Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Provides a base class for implementations of the IComparer<T> generic interface.
Assembly: mscorlib (in mscorlib.dll)
The Comparer<T> type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Compare | When overridden in a derived class, performs a comparison of two objects of the same type and returns a value indicating whether one object is less than, equal to, or greater than the other. |
![]() ![]() | Create | Creates a comparer by using the specified comparison. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IComparer::Compare | Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. |
Derive from this class to provide a custom implementation of the IComparer<T> interface for use with collection classes.
The object returned by the Default property uses the System::IComparable<T> generic interface (IComparable<T> in C#, IComparable(Of T) in Visual Basic) to compare two objects. If type T does not implement the System::IComparable<T> generic interface, the Default property returns a Comparer<T> that uses the System::IComparable interface.
Notes to ImplementersCompare and EqualityComparer<T>::Equals may behave differently in terms of culture-sensitivity and case-sensitivity.
For string comparisons, the StringComparer class is recommended over Comparer<String>. Properties of the StringComparer class return predefined instances that perform string comparisons with different combinations of culture-sensitivity and case-sensitivity. The case-sensitivity and culture-sensitivity are consistent among the members of the same StringComparer instance.
For more information on culture-specific comparisons, see the System.Globalization namespace.





