What is the Double.PositiveInfinity field in C#?
Overview
The Double.PositiveInfinity field is a field in C# that represents positive infinity. It is constant. One way to get the value of this constant is by dividing a positive number by zero.
Syntax
public const double PositiveInfinity = Infinity;
Syntax for Double.PositiveInfinity Field
Parameters
None.
Return value
This returns positive infinity value (Infinity).
Example
// use Systemusing System;// create classclass DoublePositiveInfinity{// main methodstatic void Main(){// print field valueConsole.WriteLine(Double.PositiveInfinity);// check if positive infinityif(-23/0.0 == Double.PositiveInfinity){Console.WriteLine("Positive Infinity");}else{Console.WriteLine("Not Positive Infinity");}// check if positive infinityif(23/0.0 == Double.PositiveInfinity){Console.WriteLine("Positive Infinity");}else{Console.WriteLine("Not Positive Infinity");}}}
Explanation
-
Line 10: We print the value of the field
Double.PositiveInfinity. -
Line 13–24: We check if
-23/0.023/0.0are positive infinity and print the results.