两者之间的区别是什么?我应该在什么时候使用它们呢?
发布于 2012-05-28 22:06:34
没有。
string.ToLower在幕后调用TextInfo.ToLower。
来自String.cs:
// Creates a copy of this string in lower case.
public String ToLower() {
return this.ToLower(CultureInfo.CurrentCulture);
}
// Creates a copy of this string in lower case. The culture is set by culture.
public String ToLower(CultureInfo culture) {
if (culture==null) {
throw new ArgumentNullException("culture");
}
return culture.TextInfo.ToLower(this);
} 发布于 2012-05-28 22:05:15
字符串上的ToLower和ToLowerInvariant方法在调用时实际调用TextInfo虚拟属性。由于这个原因,它们总是带有这种虚拟财产访问的开销。字符串类型的方法在结果值上没有区别,但在某些情况下速度较慢。
为了简单起见,使用str.ToLower()并忘记这个问题!
https://stackoverflow.com/questions/10785896
复制相似问题