StringComparer.CurrentCultureIgnoreCase StringComparer.CurrentCultureIgnoreCase StringComparer.CurrentCultureIgnoreCase StringComparer.CurrentCultureIgnoreCase Property


取得 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.

CurrentCultureIgnoreCase屬性實際上會傳回衍生自匿名類別的執行個體StringComparer類別。The 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.