Mono Class Library: System.String Overview | Members

System.String.CompareTo Method

Returns the sort order of the current instance compared to the specified object. [Edit]

public int CompareTo (object value)

Parameters

value
The object to compare to the current instance. [Edit]

Returns

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

ValueCondition
A negative numberThe current instance is lexicographically < value.
ZeroThe current instance is lexicographically == value.
A positive number

The current instance is lexicographically > value, or value is a null reference.

[Edit]

Exceptions

TypeReason
ArgumentExceptionvalue is not a string. [Edit]

Remarks

value is required to be a string object.

Note:

The result of comparing any string (including the empty string) to a null reference is greater than zero. Uppercase letters evaluate greater than their lowercase equivalents.

The method uses the culture (if any) of the current thread to determine the ordering of individual characters. The two strings are compared on a character-by-character basis.

This method is implemented to support the IComparable interface.

[Edit]

Requirements

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