使用 string 的一些规则
使用 string 的一些规则
//z 2012-2-7 16:50:57 PM IS2120@CSDN
· Use overloads that explicitly specify the stringcomparison rules for string operations. Typically, this involves calling amethod overload that has a parameter of typeStringComparison.
对字符串操作时使用明确地指定字符串比较规则那些重载函数。
通常,这意味这调用有一个参数类型为StringComparison的重载函数。
· Use StringComparison.Ordinalor StringComparison.OrdinalIgnoreCase forcomparisons as your safe default for culture-agnostic string matching.
通过StringComparison明确指明是否区分大小(而不是使用默认的,默认的规则在各个类里可能并不一致)
· Use comparisons with StringComparison.Ordinalor StringComparison.OrdinalIgnoreCase forbetter performance.
· Use string operations that are based on StringComparison.CurrentCulture when you displayoutput to the user.
如果相应的字符串会显示给用户,那么使用基于StringComparison.CurrentCulture的字符串操作
//z 2012-2-7 16:50:57 PM IS2120@CSDN
· Use the non-linguistic StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase values insteadof string operations based onCultureInfo.InvariantCulturewhen
the comparison is linguistically irrelevant (symbolic, for example).
如果比较是语言学无关的,使用StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase (效率会更高?),而不是CultureInfo.InvariantCulture
· Use the
String.ToUpperInvariantmethod instead of the
String.ToLowerInvariantmethod when you normalize strings for comparison.
推荐使用String.ToUpperInvariant 而不是String.ToLowerInvariant
//z 2012-2-7 16:50:57 PM IS2120@CSDN
· Use an overload of the
String.Equalsmethod to test whether two strings are equal.
使用string.equals的重载方法测试两个string是否一致。
· Use
Compareand
CompareToto sort strings, not to check for equality.
将Compare和CompareTo用于对字符串进行排序,而非用于一致性检查
Avoid the following practices when you use strings:
· Do not use overloads that do not explicitly orimplicitly specify the string comparison rules for string operations.
不要使用那些没有或明或暗指定比较规则的字符串操作函数
· Do not use string operations based on StringComparison.InvariantCulture in most cases.One of the few exceptions is when you are persisting linguistically meaningfulbut culturally agnostic data.
//z 2012-2-7 16:50:57 PM IS2120@CSDN
在大多数时候都不要使用基于StringComparison.InvariantCulture的函数。
· Do not use an overload of the
String.Compareor
CompareTomethod and test for a return value of zero to determine whether two strings areequal.
不得使用String.Compare或是CompareTo通过测试返回值是否为0来判断两个字符串是否相等。
//z 2012-2-7 16:50:57 PM IS2120@CSDN
@IS2120#CNBLOGS.T2169364049[T1,L65,R1,V259]:备忘
$ € ₤ ₭ ₪ ₩ ₮ ₦ ₱ ฿ ₡ ₫ ﷼ ¥ ﷼ ₫ ₡ ฿ ₱ ₦ ₮ ₩ ₪ ₭ ₤ € $