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.
The return value is a negative number, zero, or a positive number reflecting the sort order of a as compared to b. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:
[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 A negative number a < b. Zero a == b. A 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 the negated result of 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