Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Check whether the Unicode character is a lowercase letter in C#
To check whether a Unicode character is a lowercase letter in C#, we use the Char.IsLower() method. This method examines the Unicode character and returns true if it represents a lowercase letter according to Unicode standards, and false otherwise.
Syntax
Following is the syntax for the Char.IsLower() method −
public static bool IsLower(char c)
Parameters
c − The Unicode character to evaluate
Return Value
The method returns a bool value −
trueif the character is a lowercase letterfalseif the character is not a lowercase letter
Using Char.IsLower() with Uppercase Character
The following example demonstrates checking an uppercase letter −
using System;
public class Demo {
public static void Main() {
bool res;
char val = 'K';
Console.WriteLine("Value = " + val);
res = Char.IsLower(val);
Console.WriteLine("Is the value a lowercase letter? = " + res);
}
}
The output of the above code is −
Value = K Is the value a lowercase letter? = False
Using Char.IsLower() with Lowercase Character
The following example demonstrates checking a lowercase letter −
using System;
public class Demo {
public static void Main() {
bool res;
char val = 'd';
Console.WriteLine("Value = " + val);
res = Char.IsLower(val);
Console.WriteLine("Is the value a lowercase letter? = " + res);
}
}
The output of the above code is −
Value = d Is the value a lowercase letter? = True
Using Char.IsLower() with Multiple Character Types
Here's an example testing various character types including Unicode characters −
using System;
public class Demo {
public static void Main() {
char[] characters = { 'a', 'Z', '5', '@', 'ñ', 'Ä' };
foreach (char ch in characters) {
bool isLower = Char.IsLower(ch);
Console.WriteLine($"'{ch}' is lowercase: {isLower}");
}
}
}
The output of the above code is −
'a' is lowercase: True 'Z' is lowercase: False '5' is lowercase: False '@' is lowercase: False 'ñ' is lowercase: True 'Ä' is lowercase: False
Conclusion
The Char.IsLower() method provides a reliable way to determine if a Unicode character is a lowercase letter. It works with characters from all languages and Unicode categories, making it essential for international text processing and validation in C# applications.
