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 Systemusing System;// create classclass DoubleNaN{// main methodstatic void Main(){// print field valueConsole.WriteLine(Double.NaN);// perform arithmetic operationsdouble d1 = Double.NaN + 2;double d2 = Double.NaN / Double.NaN;double d3 = 23.34 * Double.NaN;// print valuesConsole.WriteLine(d1);Console.WriteLine(d2);Console.WriteLine(d3);}}
Explanation
- Line 10: We print the value of the
Decimal.NaNfield. - Line 13–15: We perform some arithmetic operations using the field.
- Line 18–20: We print the output.