ToLowerInvariant() 有什么问题? [英] What is wrong with ToLowerInvariant()?

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

问题描述

我有以下代码行:

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

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

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() 更可靠?

Does this mean ToUpperInvariant() is more reliable?

推荐答案

Google 给出了一个指向 CA1308:将字符串规范化为大写

Google gives a hint pointing to 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 更可靠.

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天全站免登陆