Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
Converting a string to lowercase is a common task in programming. In C#, you can use the
ToLowerInvariant() method converts all the characters in a string to lowercase using the invariant culture. This means that the method will always convert the string to lowercase using the same rules, regardless of the current culture settings.
Here’s an example of how to use the
string myString = "HELLO WORLD";
string lowerCaseString = myString.ToLowerInvariant();
In this example, the
myString variable contains the string “HELLO WORLD”. The
ToLowerInvariant() method is then called on the
myString variable, and the result is stored in the
lowerCaseString variable. The
lowerCaseString variable now contains the string “hello world”.