public sealed class Comparer : IComparer
Object
ComparerThis type implements IComparer.
mscorlib
BCL
Provides the default implementation of the IComparer interface.
System.Collections Namespace
Comparer Methods
Comparer Fields
public int Compare(object a, object b);
Returns the sort order of two Object instances.
- a
- The first Object to compare.
- b
- The second Object to compare.
A Int32 containing a value that reflects the sort order of a as compared to b. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number.
[Note: A null reference is considered to compare less than any other non-null object, and equal to any other null reference, independent of the underlying Type of either object.]
Value Condition Any negative number a < b. Zero a == b. Any positive number a > b.
Exception Type Condition ArgumentException Both a and b are not null
and do not implement the IComparable interface.-or-
Both a and b are not
null
and are not assignment-compatible types.
The behavior of this method is as follows:
- If a implements the IComparable interface, returns a.CompareTo(b).
- If a does not implement the IComparable interface but b does, returns b.CompareTo(a).
- If a and b both are not
null
and do not implement the IComparable interface, ArgumentException is thrown.
System.Collections.Comparer Class, System.Collections Namespace
public static readonly Comparer Default;
Returns a new Comparer instance containing the default implementation of the IComparer interface.
This field is read-only.
System.Collections.Comparer Class, System.Collections Namespace