StringComparer.CurrentCultureIgnoreCase 属性

定义

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

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

属性值

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.

备注

仅在 Linux 和 macOS 系统上运行的 .Net Core: 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.

CurrentCultureIgnoreCase属性实际上返回派生自类的匿名类的实例 StringComparerThe 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
   Console.WriteLine(StringComparer.ReferenceEquals(stringComparer1, 
                                                    stringComparer2));
}
Private Sub CompareCurrentCultureInsensitiveStringComparers()
   Dim stringComparer1, stringComparer2 As StringComparer
   stringComparer1 = StringComparer.CurrentCultureIgnoreCase
   stringComparer2 = StringComparer.CurrentCultureIgnoreCase
   ' Displays False
   Console.WriteLine(StringComparer.ReferenceEquals(stringComparer1, _
                                                    stringComparer2))
End Sub

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

适用于