Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
communitycreator

What is Double.NegativeInfinity Field in C#?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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);
}
}
Demonstrate the use of Double.NegativeInfinity

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.

RELATED TAGS

c#
communitycreator

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring