加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 07:32:55 所属栏目:百科 来源:网络整理
导读:我有一些代码这样: If key.Equals("search",StringComparison.OrdinalIgnoreCase) Then DoSomething()End If 我不在乎情况。我应该使用OrdinalIgnoreCase,InvariantCultureIgnoreCase还是CurrentCultureIgnoreCase? 从MSDN的“ New Recommendations for U
我有一些代码这样:
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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读