gpt4 book ai didi

.net - 通常最好使用 StringComparison.OrdinalIgnoreCase 或 StringComparison.InvariantCultureIgnoreCase?

转载 作者:行者123 更新时间:2023-12-03 04:23:24 26 4
gpt4 key购买 nike

我有一些这样的代码:

If key.Equals("search", StringComparison.OrdinalIgnoreCase) Then
DoSomething()
End If

我不关心这个案子。我应该使用 OrdinalIgnoreCase、InvariantCultureIgnoreCase 还是 CurrentCultureIgnoreCase?

最佳答案

<强> Newer .Net Docs now has a table to help you decide which is best to use in your situation.

来自 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.

关于.net - 通常最好使用 StringComparison.OrdinalIgnoreCase 或 StringComparison.InvariantCultureIgnoreCase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com