char c1 = 'a'; // Lowercase a
char c2 = 'b'; // Lowercase b
char c3 = 'C'; // Uppercase C
char c4 = '3'; // Digit 3// Part 1: use char.ToLower.
char lower1 = char.ToLower(c1); // a
char lower2 = char.ToLower(c2); // b
char lower3 = char.ToLower(c3); // c [changed]
char lower4 = char.ToLower(c4); // 3// Part 2: use char.ToUpper.
char upper1 = char.ToUpper(c1); // A [changed]
char upper2 = char.ToUpper(c2); // B [changed]
char upper3 = char.ToUpper(c3); // C
char upper4 = char.ToUpper(c4); // 3// Part 3: write results.
Console.WriteLine(c1 + "," + c2 + "," + c3 + "," + c4);
Console.WriteLine(lower1 + "," + lower2 + "," + lower3 + "," + lower4);
Console.WriteLine(upper1 + "," + upper2 + "," + upper3 + "," + upper4);a,b,C,3
IsLower, IsUpper. Sometimes we need to first test if a character is lowercase or uppercase. The char.IsLower and IsUpper methods in C# help here.
string test = "AxZ";
// Call IsLower and IsUpper in loop.
foreach (char value in test)
else if (char.IsUpper(value))
InvariantCulture. These 2 methods use the CultureInfo.InvariantCulture parameter internally. The letters are lowercased and uppercased the same in all globalization settings.
Performance notes. Finally, the char.ToLower and char.ToUpper methods have worse performance than a custom method that tests ASCII values. It can be worthwhile to use a custom method.
A summary. We saw examples of using char.ToLower and char.ToUpper. These are simple but useful methods for quickly testing characters.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Nov 23, 2023 (edit).