In C#, Char.IsBetween returns true when a character is greater than or equal to a low bound and less than or equal to a high bound (UTF-16 order).
Available in .NET 7+. Handy for inclusive ranges such as 'A'–'Z' or '0'–'9'.
This is a static member of System.Char. You call it with the type name, such as Char.IsBetween(...) or char.IsBetween(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass the value, then the inclusive minimum and maximum.
C#
bool ok = Char.IsBetween(c, 'A', 'Z');
Call
What it does
Char.IsBetween(c, 'A', 'Z')
True if c is between A and Z inclusive.
Char.IsBetween(c, '0', '9')
True if c is an ASCII digit.
Bounds are inclusive. Order the arguments as low then high.
Library declarations
C#
public static bool IsBetween(char c, char minInclusive, char maxInclusive);
Parameters
Parameter
Description
c
Character to test.
minInclusive
Lower bound (included).
maxInclusive
Upper bound (included).
Return Value
Return Value
Description
true
c is inside the inclusive range.
false
Outside the range.
C# Examples
Example 1 — A–Z Check
Test whether characters fall in A–Z.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsBetween('M', 'A', 'Z'));
Console.WriteLine(Char.IsBetween('m', 'A', 'Z'));
}
}
Output
True
False
How It Works
Upper M. Inside A–Z.
Lower m. Outside that uppercase range.
Inclusive bounds. A and Z themselves would also pass.
.NET 7+. Newer convenience API.
Example 2 — 0–9 Check
Validate ASCII digits with IsBetween.
C#
using System;
class Program {
static void Main() {
char c = '7';
Console.WriteLine(Char.IsBetween(c, '0', '9'));
Console.WriteLine(Char.IsAsciiDigit(c));
}
}
Output
True
True
How It Works
Seven in range. Between 0 and 9.
AsciiDigit agrees. Same idea for digits.
Inclusive. 0 and 9 are valid.
Readable range. IsBetween states the interval clearly.
Example 3 — Between G and P
Use a custom inclusive letter window.
C#
using System;
class Program {
static void Main() {
foreach (char ch in "GHOST") {
Console.WriteLine(ch + ": " + Char.IsBetween(ch, 'G', 'P'));
}
}
}