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 System
using System;
// create class
class DoubleNegativeInfinity
{
// main method
static void Main()
{
// print field value
Console.WriteLine(Double.NegativeInfinity);
// check if negative infinity
string result1 = -23/0.0 == Double.NegativeInfinity ? "Negative Infinity"
: "Not Negative Infinity";
Console.WriteLine(result1);
// check if negative infinity
string 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.0 23/0.0 are negative infinity. If true, we print that it is, else we print otherwise to the console.

Free Resources