我有一些这样的代码:
If key.Equals("search", StringComparison.OrdinalIgnoreCase) Then
DoSomething()
End If
我不关心这个案子.我应该使用 OrdinalIgnoreCase、InvariantCultureIgnoreCase 还是 CurrentCultureIgnoreCase?
I don't care about the case. Should I use OrdinalIgnoreCase, InvariantCultureIgnoreCase, or CurrentCultureIgnoreCase?
较新的 .Net Docs 现在有一个表格可以帮助您确定最适合您的情况.
来自 MSDN 的新建议在 Microsoft .NET 2.0 中使用字符串"
总结:以前使用 InvariantCulture 进行字符串比较、大小写和排序的代码所有者应该强烈考虑在 Microsoft .NET 2.0 中使用一组新的 String 重载.具体而言,设计为与文化无关和语言无关的数据应开始使用 StringComparison.Ordinal 或 StringComparison.OrdinalIgnoreCase 成员指定重载新的 StringComparison 枚举.这些强制执行类似于 strcmp 的逐字节比较,不仅避免了基本符号字符串的语言解释错误,而且提供了更好的性能.
Summary: Code owners previously using the
InvariantCulturefor string comparison, casing, and sorting should strongly consider using a new set ofStringoverloads in Microsoft .NET 2.0. Specifically, data that is designed to be culture-agnostic and linguistically irrelevant should begin specifying overloads using either theStringComparison.OrdinalorStringComparison.OrdinalIgnoreCasemembers of the newStringComparisonenumeration. These enforce a byte-by-byte comparison similar tostrcmpthat not only avoids bugs from linguistic interpretation of essentially symbolic strings, but provides better performance.
这篇关于通常最好使用哪个 - StringComparison.OrdinalIgnoreCase 或 StringComparison.InvariantCultureIgnoreCase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
读取 XML 时忽略空格Ignore whitespace while reading XML(读取 XML 时忽略空格)
使用 HTMLAgilityPack 仅提取页面文本extracting just page text using HTMLAgilityPack(使用 HTMLAgilityPack 仅提取页面文本)
C# 从 XML 中提取数据C# extracting data from XML(C# 从 XML 中提取数据)
读取 XML(从字符串)并获取一些字段 - 读取 XML 时出Read a XML (from a string) and get some fields - Problems reading XML(读取 XML(从字符串)并获取一些字段 - 读取 XML 时出现问题)
在 .net 中读取大型 XML 文档Reading large XML documents in .net(在 .net 中读取大型 XML 文档)
如何使用 .NET API 在 Google Drive 中创建文件夹?How to create folder in Google Drive using .NET API?(如何使用 .NET API 在 Google Drive 中创建文件夹?)