What is Double.NegativeInfinity Field in C#?
Overview
This is a field in C# that represents negative infinity. It is constant. One way to get the value of this constant is by dividing a negative number by zero.
Syntax
public const double NegativeInfinity = -Infinity;
Syntax for Double.NegativeInfinity Field
Parameters
None.
Return value
This field has the value negative infinity (-Infinity).
Code example
// use Systemusing System;// create classclass DoubleNegativeInfinity{// main methodstatic void Main(){// print field valueConsole.WriteLine(Double.NegativeInfinity);// check if negative infinitystring result1 = -23/0.0 == Double.NegativeInfinity ? "Negative Infinity": "Not Negative Infinity";Console.WriteLine(result1);// check if negative infinitystring result2 = 23/0.0 == Double.NegativeInfinity ? "Negative Infinity": "Not Negative Infinity";Console.WriteLine(result2);}}
Explanation
-
Line 10: We print the value of the field
Double.NegativeInfinity. -
Line 13 and line 20: We check if
-23/0.023/0.0are negative infinity. If true, we print that it is, else we print otherwise to the console.