The difference between string.ToLower and TextInfo.ToLower

What is the difference between the two? And when should you use each of them?

+6
source share
2 answers

Not.

string.ToLower invokes TextInfo.ToLower backstage.

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); } 
+2
source

The ToLower and ToLowerInvariant methods in strings are actually called in the TextInfo virtual property when called . For this reason, they always bear the overhead of accessing this virtual property. String type methods do not differ in the values โ€‹โ€‹of the result, but in some cases they are slower.

Full article + Benchmark

For simplicity, use str.ToLower() and forget about the problem!

+2
source

Source: https://habr.com/ru/post/916848/


All Articles