C# Char IsLetterOrDigit() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

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');
CallWhat 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

ParameterDescription
cCharacter to test.
s, indexOptional string index overload.

Return Value

Return ValueDescription
trueLetter or decimal digit.
falseAnything 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('!'));
    }
}

How It Works

  1. Letter path. A counts as a letter.
  2. Digit path. 9 counts as a digit.
  3. Punctuation out. Exclamation mark fails.
  4. 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);
    }
}

How It Works

  1. Mixed input. Letters, underscore, digits, and bang.
  2. Filter. Only letter/digit chars are kept.
  3. Underscore gone. _ is neither letter nor digit.
  4. 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));
    }
}

How It Works

  1. Unicode letter. é is a letter, so IsLetterOrDigit is true.
  2. ASCII-only helper. IsAsciiLetterOrDigit rejects it.
  3. .NET 7+. ASCII helpers need a newer runtime.
  4. Policy choice. Pick Unicode or ASCII based on your format rules.

Frequently Asked Questions

No. Test for _ yourself if needed.
No.
Yes for letters and decimal digits.
IsAsciiLetterOrDigit in .NET 7+.
Yes: Char.IsLetterOrDigit(s, index).

Next: IsLower()

Return true when the character is a lowercase letter with System.Char.

IsLower() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful