เมธอด Char.IsDigit() ใน C# บ่งชี้ว่าอักขระ Unicode ที่ระบุจัดอยู่ในประเภทตัวเลขฐานสิบ (decimal digit) หรือไม่
ไวยากรณ์
public static bool IsDigit (char ch);
พารามิเตอร์ ch คืออักขระ Unicode ที่ต้องการประเมิน
ตัวอย่าง
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
ตัวอย่างที่ 2 (ตัวเลข)
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