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 System
using System;
// create class
class DoublePositiveInfinity
{
// main method
static void Main()
{
// print field value
Console.WriteLine(Double.PositiveInfinity);
// check if positive infinity
if(-23/0.0 == Double.PositiveInfinity){
Console.WriteLine("Positive Infinity");
}else{
Console.WriteLine("Not Positive Infinity");
}
// check if positive infinity
if(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.0 23/0.0 are positive infinity and print the results.

Free Resources