有什么不对ToLowerInvariant()? [英] What is wrong with ToLowerInvariant()?

查看:360
本文介绍了有什么不对ToLowerInvariant()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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 ;)

这篇关于有什么不对ToLowerInvariant()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆