IComparer Interface

Namespace: System.Collections

Defines a method that compares two objects.

Usage

C#
VB.NET
public interface IComparer
Public Interface IComparer

Members

The IComparer interface exposes the following members:

Remarks

The IComparer interface is used by generic and non-generic collection classes to perform comparisons. For example, List<T> and ArrayList use IComparer to sort collections.

You can implement IComparer to create custom sorting logic for your own objects or to provide a specific sort order for existing objects.

Note: The CompareObject(Object x, Object y) method has been deprecated starting with .NET Framework 4.5. Use the generic IComparer<T> interface and its Compare(T x, T y) method instead.

Requirements

Namespace:
System.Collections
Assembly:
mscorlib.dll, System.Collections.dll

See Also