C#-এ Double.IsNaN() মেথডটি নির্দিষ্ট ডাবল মানটি NaN (Not a Number) কিনা তা যাচাই করতে ব্যবহৃত হয়। এটি একটি বুলিয়ান মান রিটার্ন করে—যদি মান NaN হয় তবে true, অন্যথায় false।
সিনট্যাক্স
public static bool IsNaN (double val);
এখানে val হলো যাচাই করার জন্য ডাবল-প্রিসিশন ফ্লোটিং-পয়েন্ট নম্বর।
উদাহরণ ১
এই উদাহরণে 1.0/0.0 অপারেশন করলে Positive Infinity প্রাপ্ত হয়, যা NaN নয়।
using System;
public class Demo {
public static void Main(){
double d = 1.0/0.0;
Console.WriteLine("Double Value = " + d);
Console.WriteLine("HashCode of Double Value = " + d.GetHashCode());
TypeCode type = d.GetTypeCode();
Console.WriteLine("TypeCode of Double Value = " + type);
Console.WriteLine("Positive Infinity? = " + Double.IsInfinity(d));
Console.WriteLine("Check whether the specified value is NaN? = " + Double.IsNaN(d));
}
}
আউটপুট
Double Value = ∞ HashCode of Double Value = 2146435072 TypeCode of Double Value = Double Positive Infinity? = True Check whether the specified value is NaN? = False
উদাহরণ ২
এখানে 0.0/0 অপারেশন করলে NaN প্রাপ্ত হয়।
using System;
public class Demo {
public static void Main(){
double d = 0.0/0;
Console.WriteLine("Double Value = " + d);
Console.WriteLine("HashCode of Double Value = " + d.GetHashCode());
TypeCode type = d.GetTypeCode();
Console.WriteLine("TypeCode of Double Value = " + type);
Console.WriteLine("Positive Infinity? = " + Double.IsInfinity(d));
Console.WriteLine("Check whether the specified value is NaN? = " + Double.IsNaN(d));
}
}
আউটপুট
Double Value = NaN HashCode of Double Value = -524288 TypeCode of Double Value = Double Positive Infinity? = False Check whether the specified value is NaN? = True