Permalink
Fetching contributors…
Cannot retrieve contributors at this time
276 lines (265 sloc) 15.5 KB
<Type Name="StringComparison" FullName="System.StringComparison">
<TypeSignature Language="C#" Value="public enum StringComparison" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi serializable sealed StringComparison extends System.Enum" />
<TypeSignature Language="DocId" Value="T:System.StringComparison" />
<TypeSignature Language="VB.NET" Value="Public Enum StringComparison" />
<TypeSignature Language="C++ CLI" Value="public enum class StringComparison" />
<TypeSignature Language="F#" Value="type StringComparison = " />
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Enum</BaseTypeName>
</Base>
<Attributes>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName>System.Runtime.InteropServices.ComVisible(true)</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0">
<AttributeName>Serializable</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Specifies the culture, case, and sort rules to be used by certain overloads of the <see cref="M:System.String.Compare(System.String,System.String)" /> and <see cref="M:System.String.Equals(System.Object)" /> methods.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.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.
> [!IMPORTANT]
> When you call a string comparison method such as <xref:System.String.Compare%2A?displayProperty=nameWithType>, <xref:System.String.Equals%2A?displayProperty=nameWithType>, or <xref:System.String.IndexOf%2A?displayProperty=nameWithType>, you should always call an overload that includes a parameter of type <xref:System.StringComparison> so that you can specify the type of comparison that the method performs. For more information, see [Best Practices for Using Strings](~/docs/standard/base-types/best-practices-strings.md).
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 <xref:System.Char> in the string. An ordinal comparison is fast but culture-insensitive. When you use ordinal sort rules to sort strings that start with Unicode characters (U+), the string U+xxxx comes before the string U+yyyy if the value of xxxx is numerically less than yyyy.
For more information about comparisons, see the <xref:System.String?displayProperty=nameWithType> class remarks. For more information about culture, see the <xref:System.Globalization.CultureInfo?displayProperty=nameWithType> class remarks. For guidelines on when to use ordinal or culture-sensitive comparison rules or the rules of the invariant culture, see [Best Practices for Using Strings](~/docs/standard/base-types/best-practices-strings.md). For a set of text files that contain information on the character weights used in sorting and comparison operations for Windows operating systems, see [Sorting Weight Tables](https://www.microsoft.com/en-us/download/details.aspx?id=10921).
## Examples
The following example compares four sets of words by using each member of the <xref:System.StringComparison> enumeration. The comparisons use the conventions of the English (United States) and Sami, Nothern (Sweden) cultures. Note that the strings "encyclopædia" and "encyclopedia" are considered equivalent in the en-US culture but not in the Sami, Northern (Sweden) culture.
[!code-csharp[System.String.Equals#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.string.equals/cs/equals_ex3.cs#3)]
[!code-vb[System.String.Equals#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/equals_ex3.vb#3)]
]]></format>
</remarks>
<altmember cref="T:System.String" />
<altmember cref="M:System.String.Compare(System.String,System.String)" />
<altmember cref="M:System.Globalization.CompareInfo.Compare(System.String,System.String)" />
<altmember cref="M:System.String.CompareOrdinal(System.String,System.String)" />
<altmember cref="P:System.Globalization.CultureInfo.InvariantCulture" />
</Docs>
<Members>
<Member MemberName="CurrentCulture">
<MemberSignature Language="C#" Value="CurrentCulture" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.StringComparison CurrentCulture = int32(0)" />
<MemberSignature Language="DocId" Value="F:System.StringComparison.CurrentCulture" />
<MemberSignature Language="VB.NET" Value="CurrentCulture" />
<MemberSignature Language="C++ CLI" Value="CurrentCulture" />
<MemberSignature Language="F#" Value="CurrentCulture = 0" Usage="System.StringComparison.CurrentCulture" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.StringComparison</ReturnType>
</ReturnValue>
<MemberValue>0</MemberValue>
<Docs>
<summary>Compare strings using culture-sensitive sort rules and the current culture.</summary>
</Docs>
</Member>
<Member MemberName="CurrentCultureIgnoreCase">
<MemberSignature Language="C#" Value="CurrentCultureIgnoreCase" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.StringComparison CurrentCultureIgnoreCase = int32(1)" />
<MemberSignature Language="DocId" Value="F:System.StringComparison.CurrentCultureIgnoreCase" />
<MemberSignature Language="VB.NET" Value="CurrentCultureIgnoreCase" />
<MemberSignature Language="C++ CLI" Value="CurrentCultureIgnoreCase" />
<MemberSignature Language="F#" Value="CurrentCultureIgnoreCase = 1" Usage="System.StringComparison.CurrentCultureIgnoreCase" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.StringComparison</ReturnType>
</ReturnValue>
<MemberValue>1</MemberValue>
<Docs>
<summary>Compare strings using culture-sensitive sort rules, the current culture, and ignoring the case of the strings being compared.</summary>
</Docs>
</Member>
<Member MemberName="InvariantCulture">
<MemberSignature Language="C#" Value="InvariantCulture" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.StringComparison InvariantCulture = int32(2)" />
<MemberSignature Language="DocId" Value="F:System.StringComparison.InvariantCulture" />
<MemberSignature Language="VB.NET" Value="InvariantCulture" />
<MemberSignature Language="C++ CLI" Value="InvariantCulture" />
<MemberSignature Language="F#" Value="InvariantCulture = 2" Usage="System.StringComparison.InvariantCulture" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.StringComparison</ReturnType>
</ReturnValue>
<MemberValue>2</MemberValue>
<Docs>
<summary>Compare strings using culture-sensitive sort rules and the invariant culture.</summary>
</Docs>
</Member>
<Member MemberName="InvariantCultureIgnoreCase">
<MemberSignature Language="C#" Value="InvariantCultureIgnoreCase" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.StringComparison InvariantCultureIgnoreCase = int32(3)" />
<MemberSignature Language="DocId" Value="F:System.StringComparison.InvariantCultureIgnoreCase" />
<MemberSignature Language="VB.NET" Value="InvariantCultureIgnoreCase" />
<MemberSignature Language="C++ CLI" Value="InvariantCultureIgnoreCase" />
<MemberSignature Language="F#" Value="InvariantCultureIgnoreCase = 3" Usage="System.StringComparison.InvariantCultureIgnoreCase" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.StringComparison</ReturnType>
</ReturnValue>
<MemberValue>3</MemberValue>
<Docs>
<summary>Compare strings using culture-sensitive sort rules, the invariant culture, and ignoring the case of the strings being compared.</summary>
</Docs>
</Member>
<Member MemberName="Ordinal">
<MemberSignature Language="C#" Value="Ordinal" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.StringComparison Ordinal = int32(4)" />
<MemberSignature Language="DocId" Value="F:System.StringComparison.Ordinal" />
<MemberSignature Language="VB.NET" Value="Ordinal" />
<MemberSignature Language="C++ CLI" Value="Ordinal" />
<MemberSignature Language="F#" Value="Ordinal = 4" Usage="System.StringComparison.Ordinal" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.StringComparison</ReturnType>
</ReturnValue>
<MemberValue>4</MemberValue>
<Docs>
<summary>Compare strings using ordinal (binary) sort rules.</summary>
</Docs>
</Member>
<Member MemberName="OrdinalIgnoreCase">
<MemberSignature Language="C#" Value="OrdinalIgnoreCase" />
<MemberSignature Language="ILAsm" Value=".field public static literal valuetype System.StringComparison OrdinalIgnoreCase = int32(5)" />
<MemberSignature Language="DocId" Value="F:System.StringComparison.OrdinalIgnoreCase" />
<MemberSignature Language="VB.NET" Value="OrdinalIgnoreCase" />
<MemberSignature Language="C++ CLI" Value="OrdinalIgnoreCase" />
<MemberSignature Language="F#" Value="OrdinalIgnoreCase = 5" Usage="System.StringComparison.OrdinalIgnoreCase" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.10.0</AssemblyVersion>
<AssemblyVersion>4.0.20.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.StringComparison</ReturnType>
</ReturnValue>
<MemberValue>5</MemberValue>
<Docs>
<summary>Compare strings using ordinal (binary) sort rules and ignoring the case of the strings being compared.</summary>
</Docs>
</Member>
</Members>
</Type>