要检查指定的Unicode字符是字母还是十进制数字,代码如下-
using System; public class Demo { public static void Main() { bool res; char val = '1'; Console.WriteLine("Value = "+val); res = Char.IsLetterOrDigit(val); Console.WriteLine("Is the value a letter or digit? = "+res); } }
输出结果
这将产生以下输出-
Value = 1 Is the value a letter or digit? = True
让我们看另一个例子-
using System; public class Demo { public static void Main() { bool res; char val = '$'; Console.WriteLine("Value = "+val); res = Char.IsLetterOrDigit(val); Console.WriteLine("Is the value a letter or digit? = "+res); } }
输出结果
这将产生以下输出-
Value = $ Is the value a letter or digit? = False