我有一些代码这样:
If key.Equals("search",StringComparison.OrdinalIgnoreCase) Then DoSomething() End If
我不在乎情况。我应该使用OrdinalIgnoreCase,InvariantCultureIgnoreCase还是CurrentCultureIgnoreCase?
从MSDN的“
New Recommendations for Using Strings in Microsoft .NET 2.0”
原文链接:https://www.f2er.com/vb/256613.htmlSummary: Code owners prevIoUsly using the InvariantCulture for string comparison,casing,and sorting should strongly consider using a new set of String overloads in Microsoft .NET 2.0. Specifically,data that is designed to be culture-agnostic and linguistically irrelevant should begin specifying overloads using either the StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase members of the new StringComparison enumeration. These enforce a byte-by-byte comparison similar to strcmp that not only avoids bugs from linguistic interpretation of essentially symbolic strings,but provides better performance. (15 printed pages)