Defines a method that compares two objects.
public interface IComparer
Public Interface IComparer
The IComparer interface exposes the following members:
Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
int Compare(object x, object y);
A signed integer that indicates the relative order of the objects being compared.
x precedes y in sort order.x and y are equal in sort order.x follows y in sort order.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.
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.