Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#
communitycreator

What is the Double.PositiveInfinity 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

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

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.

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