CompareOrdinal Method (String, String)
Collapse the table of content
Expand the table of content

String.CompareOrdinal Method (String, String)

 

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

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static member CompareOrdinal : 
        strA:string *
        strB:string -> int

Parameters

strA
Type: System.String

The first string to compare.

strB
Type: System.String

The second string to compare.

Return Value

Type: System.Int32

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.

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 Compare(String, String, StringComparison) method with the comparisonType argument set to StringComparison.OrdinalIgnoreCase.

Because 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.

The following example performs and ordinal comparison of two strings that only differ in case.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft