Partager via


StringComparison Enumeration

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Specifies the culture, case, and sort rules to be used by certain overloads of the String.Compare and String.Equals methods.

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public Enumeration StringComparison
[ComVisibleAttribute(true)]
public enum StringComparison

Members

Member name Description
Supported by Silverlight for Windows PhoneSupported by Xbox 360 CurrentCulture Compare strings using culture-sensitive sort rules and the current culture.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 CurrentCultureIgnoreCase Compare strings using culture-sensitive sort rules, the current culture, and ignoring the case of the strings being compared.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 InvariantCulture Compare strings using culture-sensitive sort rules and the invariant culture.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 InvariantCultureIgnoreCase Compare strings using culture-sensitive sort rules, the invariant culture, and ignoring the case of the strings being compared.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 Ordinal Compare strings using ordinal sort rules.
Supported by Silverlight for Windows PhoneSupported by Xbox 360 OrdinalIgnoreCase Compare strings using ordinal sort rules and ignoring the case of the strings being compared.

Remarks

The StringComparison enumeration is used to specify whether a string comparison should use the current culture or the invariant culture, word or ordinal sort rules, and be case-sensitive or case-insensitive.

An operation that uses word sort rules performs a culture-sensitive comparison wherein certain nonalphanumeric Unicode characters might have special weights assigned to them. Using word sort rules and the conventions of a specific culture, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list.

An operation that uses ordinal sort rules performs a comparison based on the numeric value (Unicode code point) of each Char in the string. An ordinal comparison is fast, but culture-insensitive. Using ordinal sort rules a string that starts with some Unicode character, U+xxxx, comes before a string that starts with some Unicode character, U+yyyy, if the value of xxxx is numerically less than yyyy.

For more information about comparisons, see the System.String class remarks. For more information about culture, see the System.Globalization.CultureInfo class remarks.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.