เมธอด Char.IsNumber() ใน C# ใช้สำหรับระบุว่าอักขระ Unicode ที่ระบุจัดอยู่ในประเภทตัวเลขหรือไม่
ไวยากรณ์
public static bool IsNumber (char ch);
พารามิเตอร์ ch คืออักขระ Unicode ที่ต้องการประเมิน
ตัวอย่าง
using System;
public class Demo {
public static void Main(){
bool res;
char val = '2';
Console.WriteLine("Value = " + val);
res = Char.IsNumber(val);
Console.WriteLine("Is the value a number? = " + res);
}
}ผลลัพธ์
Value = 2 Is the value a number? = True
ตัวอย่างที่ 2 (อักขระไม่ใช่ตัวเลข)
using System;
public class Demo {
public static void Main(){
bool res;
char val = 'P';
Console.WriteLine("Value = " + val);
res = Char.IsNumber(val);
Console.WriteLine("Is the value a number? = " + res);
}
}ผลลัพธ์
Value = P Is the value a number? = False