Skip to main content
.NET Framework Class Library
String..::.Compare Method





Updated: December 2010

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

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

Overload List
 NameDescription
Public methodStatic memberCompare(String, String)Compares two specified String objects and returns an integer that indicates their relative position in the sort order.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Public methodStatic memberCompare(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.
Top
Remarks
Caution noteCaution

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.

Change History

Date

History

Reason

December 2010

Added the Remarks section.

Information enhancement.

Microsoft is conducting an online survey to understand your opinion of the MSDN Web site. If you choose to participate, the online survey will be presented to you when you leave the MSDN Web site.

Would you like to participate?