C# How to Convert String to Lowercase - Simple Example
In C#, you can convert a string to lowercase by using the
ToLower() method like this: string lower = originalString.ToLower();.Examples
InputHELLO
Outputhello
InputHello World!
Outputhello world!
Input123 ABC xyz
Output123 abc xyz
How to Think About It
To convert a string to lowercase, think of changing every uppercase letter to its lowercase version while leaving other characters unchanged. The
ToLower() method does this for you by scanning the string and replacing uppercase letters with lowercase ones.Algorithm
1
Get the input string.2
Call the method that converts all uppercase letters to lowercase.3
Return or store the new lowercase string.Code
csharp
using System; class Program { static void Main() { string original = "Hello World!"; string lower = original.ToLower(); Console.WriteLine(lower); } }
Output
hello world!
Dry Run
Let's trace converting "Hello World!" to lowercase using ToLower()
1
Original string
original = "Hello World!"
2
Convert to lowercase
lower = original.ToLower() -> "hello world!"
3
Print result
Output: "hello world!"
| Step | String Value |
|---|---|
| Initial | Hello World! |
| After ToLower() | hello world! |
Why This Works
Step 1: Use ToLower() method
The ToLower() method is built into C# strings and converts all uppercase letters to lowercase.
Step 2: Returns new string
It does not change the original string but returns a new string with lowercase letters.
Step 3: Non-letter characters unchanged
Characters like numbers, spaces, and punctuation stay the same.
Alternative Approaches
ToLowerInvariant() method
csharp
using System; class Program { static void Main() { string original = "Hello World!"; string lower = original.ToLowerInvariant(); Console.WriteLine(lower); } }
This method converts to lowercase using a culture-independent rule, useful for consistent results regardless of user locale.
Complexity: O(n) time, O(n) space
Time Complexity
The method processes each character once, so time grows linearly with string length.
Space Complexity
A new string is created to hold the lowercase result, so space also grows linearly.
Which Approach is Fastest?
ToLower() and ToLowerInvariant() have similar performance; choose based on culture needs.
| Approach | Time | Space | Best For |
|---|---|---|---|
| ToLower() | O(n) | O(n) | Culture-sensitive lowercase conversion |
| ToLowerInvariant() | O(n) | O(n) | Culture-independent lowercase conversion |
Use
ToLowerInvariant() if you want culture-independent lowercase conversion.Forgetting that
ToLower() returns a new string and does not change the original string.