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

屬性值

字串比較的新物件。A new object for string comparison.

備註

目前的文化CultureInfo.CurrentCulture特性是CultureInfo與目前線程相關聯的物件; 屬性會傳回它。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 StringComparer存取子的每個呼叫都會傳回新的物件,如下列程式碼所示。 getEach 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物件儲存在本機變數中,而不是多次抓取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.

適用於

另請參閱