Double.IsInfinity() 方法在 C# 中
C# 中的 Double.IsInfinity() 方法用于返回一个值,指示指定数字的评估结果是负无穷大还是正无穷大。
语法
语法如下 −
public static bool IsInfinity (double d);
上述中,值 d 是一个双精度浮点数。
示例
我们现在来看一个示例 −
using System; public class Demo { public static void Main(){ double d = 5.5; 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)); } }
输出
这将产生以下输出 −
Double Value = 5.5 HashCode of Double Value = 1075183616 TypeCode of Double Value = Double Positive Infinity? = False
示例
我们现在来看另一个示例 −
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)); } }
输出
这将产生以下输出 −
Double Value = ∞ HashCode of Double Value = 2146435072 TypeCode of Double Value = Double Positive Infinity? = True
广告