gpt4 book ai didi

c# - ToLowerInvariant() 有什么问题?

转载 作者:IT王子 更新时间:2023-10-29 03:46:30 27 4
gpt4 key购买 nike

我有以下代码行:

var connectionString = configItems.
Find(item => item.Name.ToLowerInvariant() == "connectionstring");

VS 2010 代码分析告诉我以下内容:

Warning 7 CA1308 : Microsoft.Globalization : In method ... replace the call to 'string.ToLowerInvariant()' with String.ToUpperInvariant().

这是否意味着 ToUpperInvariant() 更可靠?

最佳答案

Google 给出了指向 CA1308: Normalize strings to uppercase 的提示

它说:

Strings should be normalized to uppercase. A small group of characters, when they are converted to lowercase, cannot make a round trip. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters.

所以,是的 - ToUpper 比 ToLower 更可靠。

在未来,我建议首先使用谷歌搜索 - 我会针对我收到的所有那些 FxCop 警告这样做;)有助于阅读相应的文档;)

关于c# - ToLowerInvariant() 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2801508/

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