เมธอด Double.IsNaN() ใน C# ใช้สำหรับคืนค่าบอกว่าค่าที่ระบุเป็น Not-a-Number (NaN) หรือไม่
Syntax
public static bool IsNaN (double val);
พารามิเตอร์ val คือ Double-precision Floating-point Number
ตัวอย่าง
using System;
public class Demo {
public static void Main(){
double d = 1.0 / 0.0;
Console.WriteLine("Double Value = " + d);
Console.WriteLine("HashCode of Double Value = " + d.GetHashCode());
TypeCode type = d.GetTypeCode();
Console.WriteLine("TypeCode of Double Value = " + type);
Console.WriteLine("Positive Infinity? = " + Double.IsInfinity(d));
Console.WriteLine("Check whether the specified value is NaN? = " + Double.IsNaN(d));
}
}
ผลลัพธ์
Double Value = ∞ HashCode of Double Value = 2146435072 TypeCode of Double Value = Double Positive Infinity? = True Check whether the specified value is NaN? = False
ตัวอย่างเพิ่มเติม
using System;
public class Demo {
public static void Main(){
double d = 0.0 / 0;
Console.WriteLine("Double Value = " + d);
Console.WriteLine("HashCode of Double Value = " + d.GetHashCode());
TypeCode type = d.GetTypeCode();
Console.WriteLine("TypeCode of Double Value = " + type);
Console.WriteLine("Positive Infinity? = " + Double.IsInfinity(d));
Console.WriteLine("Check whether the specified value is NaN? = " + Double.IsNaN(d));
}
}
ผลลัพธ์
Double Value = NaN HashCode of Double Value = -524288 TypeCode of Double Value = Double Positive Infinity? = False Check whether the specified value is NaN? = True