System.String.CompareOrdinal Method

Compares two specified string objects by evaluating the numeric values of the corresponding char objects in each string.


public static int CompareOrdinal (string strA, string strB)


The first string to compare.
The second string to compare.


An integer that indicates the lexical relationship between the two comparands.

Less than zero

strA is less than strB.


strA and strB are equal.

Greater than zero

strA is greater than strB.


This method performs a case-sensitive comparison using ordinal sort rules. For more information about word, string, and ordinal sorts, see System.Globalization.CompareOptions. To perform a case-insensitive comparison using ordinal sort rules, call the string.Compare(string, string, StringComparison) method with a StringComparison value of StringComparison.OrdinalIgnoreCase.

Because string.CompareOrdinal(string, string) is a static method, strA and strB can be null. If both values are null, the method returns 0 (zero), which indicates that strA and strB are equal. If only one of the values is null, the method considers the non-null value to be greater.


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