Note that Char.IsDigit()
returns true
for many more code points than just the digits in the ASCII range 0x30 to 0x39.
For example the Thai digit characters that return true
from Char.IsDigit(): '๐' '๑' '๒' '๓' '๔' '๕' '๖' '๗' '๘' '๙'
Also there are the 'Full width' characters that Char.IsDigit()
returns true for: 0xff10
through 0xff19
. These glyphs look just like the ASCII characters 0x30-0x39
, so if you're going to accept them you should also probably accept 0xff21-0xff26
and 0xff41-0xff46
which look just like 'A'-'F' and 'a'-'f'.
If you're going to support digits that are outside of the ASCII range, your users might expect that you to support glyphs that correspond to Latin 'a'..'f' and 'A'..'F' that exist in other scripts outside of the ASCII range.
Personally, I think I'd stick with something more like:
bool isHexChar = ('0' <= c) && (c <= '9') ||
('a' <= c) && (c <= 'f') ||
('A' <= c) && (c <= 'F');
Which I think would be potentially less surprising to people.