有什么不对ToLowerInvariant()?有什么、ToLowerInvariant

2023-09-02 20:43:48 作者:ㄟ其实我不花心▓

我有code以下行:

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

VS 2010 code分析告诉我下面的:

VS 2010 code analysis is telling me the following:

警告7 CA1308:Microsoft.Globalization:在方法......与String.ToUpperInvariant调用替换为string.ToLowerInvariant()()。

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

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

推荐答案

谷歌给出了一个暗示指向 CA1308 :规范化字符串为大写

Google gives a hint pointing to CA1308: Normalize strings to uppercase

它说:

字符串应该被标准化为大写。一小群的人物,当他们被转换为小写,不能让一个往返。为了使一个往返装置中的字符从一个区域转换为重新presents字符数据不同,然后以准确地检索原始字符从转换后的文字另一个区域。

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更可靠

So, yes - ToUpper is more reliable than ToLower.

在未来我建议谷歌搜索第一 - 我做的所有这些FxCop的警告,我被抛来抛去;)有很大帮助读取相应的文件;)

In the future I suggest googling first - I do that for all those FxCop warnings I get thrown around ;) Helps a lot to read the corresponding documentation ;)