Compares two strings with the default CultureInfo information.
[Visual Basic] Overloads Public Shared Function Compare( _ ByVal strA As String, _ ByVal strB As String _ ) As Integer [C#] public static int Compare( string strA, string strB ); [C++] public: static int Compare( String* strA, String* strB ); [JScript] public static function Compare( strA : String, strB : String ) : int;
Value Type | Condition |
---|---|
A negative integer | If region A is less than region B. |
0 | If the two regions or length are equal. |
A positive integer | If region A is greater than region B. |
Exception Type | Condition |
---|---|
ArgumentNullException | If either string is null. |
The Compare method does a locale sensitive comparison of two strings and returns a integer representation of their relationship.
One string may be "less than" or "greater than" another string depending upon the rules of the national language under which the comparison is made. To compare strings without regard to national languages, see CompareOrdinal.
The comparison of strA and strB is case-sensitive and the default locale is used. This method does a CultureInfo sensitive comparison (see CurrentCulture for current cultures).
String Class | String Members | System Namespace | String.Compare Overload List | Int32