Compare Method
TOC
Collapse the table of content
Expand the table of content

String.Compare Method

 

Compares two specified String objects and returns an integer that indicates their relative position in the sort order.

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

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCompare(String, Int32, String, Int32, Int32)

Compares substrings of two specified String objects and returns an integer that indicates their relative position in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, Int32, String, Int32, Int32, Boolean)

Compares substrings of two specified String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, Int32, String, Int32, Int32, Boolean, CultureInfo)

Compares substrings of two specified String objects, ignoring or honoring their case and using culture-specific information to influence the comparison, and returns an integer that indicates their relative position in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, Int32, String, Int32, Int32, CultureInfo, CompareOptions)

Compares substrings of two specified String objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two substrings to each other in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, Int32, String, Int32, Int32, StringComparison)

Compares substrings of two specified String objects using the specified rules, and returns an integer that indicates their relative position in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, String)

Compares two specified String objects and returns an integer that indicates their relative position in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, String, Boolean)

Compares two specified String objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, String, Boolean, CultureInfo)

Compares two specified String objects, ignoring or honoring their case, and using culture-specific information to influence the comparison, and returns an integer that indicates their relative position in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, String, CultureInfo, CompareOptions)

Compares two specified String objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two strings to each other in the sort order.

System_CAPS_pubmethodSystem_CAPS_staticCompare(String, String, StringComparison)

Compares two specified String objects using the specified rules, and returns an integer that indicates their relative position in the sort order.

All overloads of the Comparemethod return a 32-bit signed integer indicating the lexical relationship between the two comparands.

Value

Condition

Less than zero

The first substring precedes the second substring in the sort order.

Zero

The substrings occur in the same position in the sort order, or length is zero.

Greater than zero

The first substring follows the second substring in the sort order.

System_CAPS_warningWarning

Whenever possible, you should call an overload of the Compare method that includes a StringComparison parameter. For more information, see Best Practices for Using Strings in the .NET Framework.

Return to top
Show:
© 2016 Microsoft