In C#, Char.IsLetterOrDigit returns true when a character is a Unicode letter or a Unicode decimal digit.
It is a convenient “alphanumeric” check for cleaning tokens, though real identifiers may also allow underscore or other rules you define yourself.
This is a static member of System.Char. You call it with the type name, such as Char.IsLetterOrDigit(...) or char.IsLetterOrDigit(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass a char to test.
C#
bool ok = Char.IsLetterOrDigit('A');
bool also = Char.IsLetterOrDigit('9');
Call
What it does
Char.IsLetterOrDigit(c)
True for letter or decimal digit.
Char.IsLetterOrDigit(s, i)
Tests s[i].
Punctuation and spaces return false.
Library declarations
C#
public static bool IsLetterOrDigit(char c);
public static bool IsLetterOrDigit(string s, int index);
Parameters
Parameter
Description
c
Character to test.
s, index
Optional string index overload.
Return Value
Return Value
Description
true
Letter or decimal digit.
false
Anything else.
C# Examples
Example 1 — Letter and Digit
Show true for A and 9, false for punctuation.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsLetterOrDigit('A'));
Console.WriteLine(Char.IsLetterOrDigit('9'));
Console.WriteLine(Char.IsLetterOrDigit('!'));
}
}
Output
True
True
False
How It Works
Letter path. A counts as a letter.
Digit path. 9 counts as a digit.
Punctuation out. Exclamation mark fails.
One helper. Combines IsLetter and IsDigit ideas.
Example 2 — Strip Symbols
Keep only letters and digits from mixed text.
C#
using System;
class Program {
static void Main() {
string raw = "user_42!";
string keep = "";
foreach (char ch in raw) {
if (Char.IsLetterOrDigit(ch)) keep += ch;
}
Console.WriteLine(keep);
}
}
Output
user42
How It Works
Mixed input. Letters, underscore, digits, and bang.
Filter. Only letter/digit chars are kept.
Underscore gone. _ is neither letter nor digit.
Result user42. Symbols disappear from the token.
Example 3 — Unicode Letter Still Passes
Compare with IsAsciiLetterOrDigit on é.
C#
using System;
class Program {
static void Main() {
char c = 'é';
Console.WriteLine(Char.IsLetterOrDigit(c));
Console.WriteLine(Char.IsAsciiLetterOrDigit(c));
}
}
Output
True
False
How It Works
Unicode letter. é is a letter, so IsLetterOrDigit is true.
ASCII-only helper. IsAsciiLetterOrDigit rejects it.
.NET 7+. ASCII helpers need a newer runtime.
Policy choice. Pick Unicode or ASCII based on your format rules.