Mono Class Library: System.Collections.Comparer Overview | Members

System.Collections.Comparer.Compare Method

Returns the sort order of two object instances. [Edit]

public int Compare (object a, object b)

Parameters

a
The first object to compare. [Edit]
b
The second object to compare. [Edit]
a
Documentation for this section has not yet been entered. [Edit]

Returns

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:

ValueCondition
A negative numbera < b.
Zeroa == b.
A positive numbera > b.

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.

[Edit]

Exceptions

TypeReason
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.

[Edit]

Remarks

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.
[Edit]

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0