What is the Double.NaN field in C#?

Overview

In C#, the Double.NaN field represents a value that is not a number. It is constant.

Syntax

public const double NaN = NaN;
Syntax for Double.NaN method

Parameters

It requires no parameters. It is a field and a constant.

Return value

It returns a NaN field.

Example

// use System
using System;
// create class
class DoubleNaN
{
// main method
static void Main()
{
// print field value
Console.WriteLine(Double.NaN);
// perform arithmetic operations
double d1 = Double.NaN + 2;
double d2 = Double.NaN / Double.NaN;
double d3 = 23.34 * Double.NaN;
// print values
Console.WriteLine(d1);
Console.WriteLine(d2);
Console.WriteLine(d3);
}
}

Explanation

  • Line 10: We print the value of the Decimal.NaN field.
  • Line 13–15: We perform some arithmetic operations using the field.
  • Line 18–20: We print the output.

Free Resources