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
Char.IsLetter() Method in C#
The Char.IsLetter() method in C# is used to determine whether a specified Unicode character is categorized as a Unicode letter. This method returns true if the character is a letter (uppercase or lowercase), and false otherwise.
This method is particularly useful for input validation, text processing, and character classification in applications where you need to distinguish letters from numbers, symbols, or other character types.
Syntax
Following is the syntax −
public static bool IsLetter(char ch);
Parameters
-
ch − The Unicode character to evaluate.
Return Value
Returns true if the character is a Unicode letter; otherwise, false.
Using Char.IsLetter() with Letters
Example
using System;
public class Demo {
public static void Main() {
bool res;
char val = 'K';
Console.WriteLine("Value = " + val);
res = Char.IsLetter(val);
Console.WriteLine("Is the value a letter? = " + res);
}
}
The output of the above code is −
Value = K Is the value a letter? = True
Using Char.IsLetter() with Numbers
Example
using System;
public class Demo {
public static void Main() {
bool res;
char val = '2';
Console.WriteLine("Value = " + val);
res = Char.IsLetter(val);
Console.WriteLine("Is the value a letter? = " + res);
}
}
The output of the above code is −
Value = 2 Is the value a letter? = False
Testing Multiple Character Types
Example
using System;
public class Demo {
public static void Main() {
char[] testChars = {'A', 'z', '5', '@', ' ', 'Ñ'};
Console.WriteLine("Character\tIsLetter()");
Console.WriteLine("-------------------------");
foreach (char ch in testChars) {
Console.WriteLine($"{ch}\t\t{Char.IsLetter(ch)}");
}
}
}
The output of the above code is −
Character IsLetter() ------------------------- A True z True 5 False @ False False Ñ True
Conclusion
The Char.IsLetter() method is a useful utility for character validation in C#. It returns true for any Unicode character classified as a letter (both uppercase and lowercase), making it ideal for input validation and text processing scenarios.
