C# Char IsAsciiDigit() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

In C#, Char.IsAsciiDigit returns true only for the ten ASCII digits '0'–'9'.

Unlike IsDigit, it rejects non-ASCII decimal digits. These ASCII helpers are available in .NET 7 and later. On older runtimes, use range checks such as c >= '0' && c <= '9'.

This is a static member of System.Char. You call it with the type name, such as Char.IsAsciiDigit(...) or char.IsAsciiDigit(...). A char holds one 16-bit UTF-16 code unit.

Syntax

Pass a character expected to be 0–9.

C#
bool ok = Char.IsAsciiDigit('5');
CallWhat it does
Char.IsAsciiDigit(c)True for ASCII 0–9.

Equivalent to c >= '0' && c <= '9'.

Library declarations
C#
public static bool IsAsciiDigit(char c);

Parameters

ParameterDescription
cCharacter to test.

Return Value

Return ValueDescription
trueASCII digit.
falseAnything else.

C# Examples

Example 1 — ASCII Digits

Test 5 and A.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Char.IsAsciiDigit('5'));
        Console.WriteLine(Char.IsAsciiDigit('A'));
    }
}

How It Works

  1. Five passes. ASCII digit.
  2. Letter fails. A is not a digit.
  3. .NET 7+. Newer helper.
  4. Strict 0–9. No other scripts.

Example 2 — Same for ASCII

Compare helpers on ASCII 7.

C#
using System;

class Program {
    static void Main() {
        char c = '7';
        Console.WriteLine(Char.IsAsciiDigit(c));
        Console.WriteLine(Char.IsDigit(c));
    }
}

How It Works

  1. Both true. ASCII digits satisfy both APIs.
  2. Difference elsewhere. Non-ASCII digits diverge.
  3. Pick strictness. ASCII-only vs Unicode digits.
  4. Same sample. Character 7 in both calls.

Example 3 — All ASCII Digits

Validate a numeric code string.

C#
using System;

class Program {
    static void Main() {
        string code = "2048";
        bool ok = true;
        foreach (char ch in code) {
            if (!Char.IsAsciiDigit(ch)) { ok = false; break; }
        }
        Console.WriteLine(ok);
    }
}

How It Works

  1. Four digits. 2048 is ASCII digits only.
  2. Loop validate. Fail on the first bad char.
  3. True result. Entire string passes.
  4. Protocol friendly. Typical for PIN-like ASCII fields.

Frequently Asked Questions

For 0–9 yes; IsDigit also allows other Unicode decimal digits.
.NET 7+.
No.
c >= '0' && c <= '9'.
Yes.

Next: IsAsciiHexDigit()

Return true for ASCII hex digits 0–9, A–F, a–f. .NET 7+ with System.Char.

IsAsciiHexDigit() 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.

7 people found this page helpful