C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Return: They return a Boolean, which you can use to test in an if-statement. If a char is not lowercase, they return false.
IfHere: The char.IsLower tests are chained in an "or" conditional. The if-statements test the chars for lowercase or uppercase letters.
Note: In the first if, the first char is lower so only that test will be executed. In the second if, the third char is upper.
And: For non-letter chars such as digits and punctuation, IsLower and IsUpper will return false.
C# program that uses char.IsLower
using System;
class Program
{
static void Main()
{
char c1 = 'a'; // Lowercase letter
char c2 = 'b'; // Lowercase letter
char c3 = 'C'; // Uppercase letter
char c4 = '3'; // Digit
if (char.IsLower(c1) || // True
char.IsLower(c2) || // True
char.IsLower(c3) || // False
char.IsLower(c4)) // False *
{
Console.WriteLine("A char is lowercase.");
}
if (char.IsUpper(c1) || // False
char.IsUpper(c2) || // False
char.IsUpper(c3) || // True
char.IsUpper(c4)) // False *
{
Console.WriteLine("A char is uppercase.");
}
}
}
Output
A char is lowercase.
A char is uppercase.
And: We saw how these methods will return false on input that is not a character such as a digit.