StringComparer.CurrentCultureIgnoreCase 属性


获取一个 StringComparer 对象,该对象使用当前区域性的单词比较规则执行不区分大小写的字符串比较。Gets a StringComparer object that performs case-insensitive string comparisons using the word comparison rules of the current culture.

 static property StringComparer ^ CurrentCultureIgnoreCase { StringComparer ^ get(); };
public static StringComparer CurrentCultureIgnoreCase { get; }
member this.CurrentCultureIgnoreCase : StringComparer
Public Shared ReadOnly Property CurrentCultureIgnoreCase As StringComparer


用于字符串比较的新对象。A new object for string comparison.


当前区域性是与当前CultureInfo线程关联的对象; 它CultureInfo.CurrentCulture由属性返回。The current culture is the CultureInfo object associated with the current thread; it is returned by the CultureInfo.CurrentCulture property.

StringComparer字符串与语言CurrentCultureIgnoreCase相关但其大小写不相关时,可以使用由属性返回的。The StringComparer returned by the CurrentCultureIgnoreCase property can be used when strings are linguistically relevant but their case is not. 例如,如果向用户显示字符串,但大小写不重要,则应使用区分区域性的、不区分大小写的字符串比较来对字符串数据进行排序。For example, if strings are displayed to the user but case is unimportant, culture-sensitive, case-insensitive string comparison should be used to order the string data.


.NET Core 仅在 Linux 和 macOS 系统上运行: C 和 Posix 区域性的排序规则行为始终区分大小写,因为这些区域性不使用预期的 Unicode 排序规则顺序。.NET Core running on Linux and macOS systems only: The collation behavior for the C and Posix cultures is always case-sensitive because these cultures do not use the expected Unicode collation order. 建议使用除 C 或 Posix 以外的区域性执行区分区域性但不区分大小写的排序操作。We recommend that you use a culture other than C or Posix for performing culture-sensitive, case-insensitive sorting operations.

属性实际上返回派生StringComparer自类的匿名类的实例。 CurrentCultureIgnoreCaseThe CurrentCultureIgnoreCase property actually returns an instance of an anonymous class derived from the StringComparer class.

对属性CurrentCultureIgnoreCase get访问器的每个调用都StringComparer将返回一个新的对象,如以下代码所示。Each call to the CurrentCultureIgnoreCase property get accessor returns a new StringComparer object, as the following code shows.

private void CompareCurrentCultureInsensitiveStringComparer()
   StringComparer stringComparer1, stringComparer2;
   stringComparer1 = StringComparer.CurrentCultureIgnoreCase;
   stringComparer2 = StringComparer.CurrentCultureIgnoreCase;
   // Displays false
Private Sub CompareCurrentCultureInsensitiveStringComparers()
   Dim stringComparer1, stringComparer2 As StringComparer
   stringComparer1 = StringComparer.CurrentCultureIgnoreCase
   stringComparer2 = StringComparer.CurrentCultureIgnoreCase
   ' Displays False
   Console.WriteLine(StringComparer.ReferenceEquals(stringComparer1, _
End Sub

若要提高性能,可以将StringComparer对象存储在局部变量中,而不是多次检索CurrentCultureIgnoreCase属性的值。To improve performance, you can store the StringComparer object in a local variable rather than retrieve the value of the CurrentCultureIgnoreCase property multiple times.