Compares this instance with the specified Object.
[Visual Basic] Overloads Overridable Public Function CompareTo( _ ByVal value As Object _ ) As Integer [C#] public virtual int CompareTo( object value ); [C++] public: virtual int CompareTo( Object* value ); [JScript] public function CompareTo( value : Object ) : int;
Value | Condition |
---|---|
A negative integer | If the object sorts before this instance. |
Zero | If the objects sort equally. |
A positive integer | If the object sorts after this instance. |
Exception Type | Condition |
---|---|
ArgumentException | If the object is not a string. |
The comparison of two string values is case-sensitive and uses the CultureInfo of the current thread to determine the ordering.
An instance of string is considered to be greater than any object that is not a string. In particular, an instance of String is considered to be greater than a null reference. Note that sorted arrays with nulls, objects, and strings would put in that order. A null string sorts less than all the others.
String Class | String Members | System Namespace | String.CompareTo Overload List | Object | Int32 | CultureInfo