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