To test if a float-point value is a NaN(Not a Number), use the method from float or double.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(double.IsNaN(0.0 / 0.0)); // True
}
}
The output:
True
We can also use the object.Equals to compare two NaN values.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(object.Equals(0.0 / 0.0, double.NaN)); // True
}
}
The output:
True