Here you see that char.ToLower converts uppercase characters to lowercase characters, while not changing characters that are already lowercase or digits. In the same example, you see char.ToUpper, which is the opposite.
Main: The 4 calls to char.ToLower show how this static method is used. The comments show the values returned by char.ToLower.
Next: The 4 calls to char.ToUpper show how this method is used. The result from each call is shown.Static
Finally: The last statement in the code example is the most complex and it is a call to WriteLine with a format string.Consolestring.Format
C# program that uses char.ToLower
static void Main()
char c1 = 'a'; // Lowercase a
char c2 = 'b'; // Lowercase b
char c3 = 'C'; // Uppercase C
char c4 = '3'; // Digit 3
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
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
c1, c2, c3, c4,
lower1, lower2, lower3, lower4,
upper1, upper2, upper3, upper4);
Sometimes it is better to first test if a character is lowercase or uppercase. Fortunately, the .NET Framework provides the char.IsLower and char.IsUpper methods, which also alias the System.Char type and are static methods.char.IsLower
Tip: These four static methods use value semantics, which means the parameter is copied to the method as a value.
Therefore: The ToLower and ToUpper methods do not modify the variable you use—they return a new value.