Double.IsFinite()方法用于检查double值是否超出范围。
Syntax: public static bool IsFinite (double value);
Return Value: This method returns the true if value is finite otherwise false.
下面的程序说明了Double.IsFinite()方法的用法:
范例1:
// C# program to demonstrate the
// Double.IsFinite() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
double value1 = 10d;
// using IsFinite() method
bool value = Double.IsFinite(value1);
// Displaying the result
if (value)
Console.WriteLine("{0} is finite", value1);
else
Console.WriteLine("{0} is not finite", value1);
}
}
输出:
10 is finite
范例2:
// C# program to demonstrate the
// Double.IsFinite() Method
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
double value1 = Math.Pow(2, 1000000000000);
// using IsFinite() method
bool value = Double.IsFinite(value1);
// Displaying the result
if (value)
Console.WriteLine("{0} is finite", value1);
else
Console.WriteLine("{0} is not finite", value1);
}
}
输出:
Infinity is not finite