IComparer Interface

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Exposes a method that compares two objects.

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

[<ComVisibleAttribute(true)>]
type IComparer = interface end

NameDescription
System_CAPS_pubmethodCompare(Object, Object)

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

This interface is used in conjunction with the Array.Sort and Array.BinarySearch methods. It provides a way to customize the sort order of a collection. See the Compare method for notes on parameters and return value.

The default implementation of this interface is the Comparer class. For the generic version of this interface, see System.Collections.Generic.IComparer<'T>.

The following code example demonstrates the use of the IComparer interface to sort an ArrayList object. In this example, the IComparer interface is implemented using the CaseInsensitiveComparer class to reverse the order of the contents of the ArrayList.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: