C# 中的 Char.IsDigit() 方法
csharpserver side programmingprogramming更新于 2025/9/18 5:22:00
C# 中的 Char.IsDigit() 方法指示指定的 Unicode 字符是否属于十进制数字。
语法
以下是语法 −
public static bool IsDigit (char ch);
上面,参数 ch 是要评估的 Unicode 字符。
示例
现在让我们看一个实现 Char.IsDigit() 方法的示例 −
using System;
public class Demo {
public static void Main(){
bool res;
char val = 'g';
Console.WriteLine("Value = "+val);
res = Char.IsDigit(val);
Console.WriteLine("Is the value a digit? = "+res);
}
}
输出
这将产生以下输出 −
Value = g Is the value a digit? = False
示例
现在让我们看另一个例子 −
using System;
public class Demo {
public static void Main(){
bool res;
char val = '2';
Console.WriteLine("Value = "+val);
res = Char.IsDigit(val);
Console.WriteLine("Is the value a digit? = "+res);
}
}
输出
这将产生以下输出 −
Value = 2 Is the value a digit? = True

