C# String CompareOrdinal(String, String)
Description
String CompareOrdinal(String, String)
compares two
specified String objects by evaluating the numeric values of the corresponding
Char objects in each string.
Syntax
String.CompareOrdinal(String, String)
has the following syntax.
public static int CompareOrdinal(
string strA,
string strB
)
Parameters
String.CompareOrdinal(String, String)
has the following parameters.
strA
- The first string to compare.strB
- The second string to compare.
Returns
String.CompareOrdinal(String, String)
method returns An integer that indicates the lexical relationship between the two comparands.
Value Condition Less than zero strA is less than strB. Zero strA and strB are
equal. Greater than zero strA is greater than strB.
Example
The following example performs and ordinal comparison of two strings that only differ in case. Compare the numeric values of the corresponding Char objects in each string.
using System;//from ww w . j av a 2s. c om
class Sample {
public static void Main() {
String str1 = "ABCD";
String str2 = "abcd";
String str;
int result;
Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2);
result = String.CompareOrdinal(str1, str2);
str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
Console.Write(str);
}
}
The code above generates the following result.