vb.net – 一般最好使用 – StringComparison.OrdinalIgnoreCase或StringComparison.InvariantCultureIgnoreCase?

前端之家收集整理的这篇文章主要介绍了vb.net – 一般最好使用 – StringComparison.OrdinalIgnoreCase或StringComparison.InvariantCultureIgnoreCase?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些代码这样:
If key.Equals("search",StringComparison.OrdinalIgnoreCase) Then
    DoSomething()
End If

我不在乎情况。我应该使用OrdinalIgnoreCase,InvariantCultureIgnoreCase还是CurrentCultureIgnoreCase?

从MSDN的“ New Recommendations for Using Strings in Microsoft .NET 2.0

Summary: 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)

原文链接:https://www.f2er.com/vb/256613.html

猜你在找的VB相关文章