C# 中的 Double.IsNaN() 方法
C# 中的 Double.IsNaN() 方法用于返回一个值,以指示指定的值是否不是数字 (NaN)。
语法
语法如下 −
public static bool IsNaN (double val);
以上,val 是双精度浮点数。
示例
现在我们看示例 −
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
广告