What is the difference between the two? And when should I use each of them?
There is none.
string.ToLower
calls TextInfo.ToLower
behind the scenes.
From 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);
}
The ToLower and ToLowerInvariant methods on strings actually call into the TextInfo virtual property when invoked. For this reason, they always carry the overhead of this virtual property access. The string type methods have no difference in result values but are slower in some cases.
The full article + Benchmark
For the sake of simplicity use str.ToLower()
and forget about the issue!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With