To answer your question, I suggest you use nullable double type for X and then you will be able to check for null. Here is one example:
double? x = null;
if (null == x)
{
//-- this means x is null
}
else if (x.GetValueOrDefault() == 0)
{
//-- this means x is either null or 0 value
}
else
{
//-- this means x is neither null nor 0, it has some value other than 0
}
नमस्ते,
[KaushaL] BlogTwitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
Member
209 Points
701 Posts
How to check if double variable is blank (null) or 0 (zero).
Sep 06, 2017 09:51 AM|gani7787|LINK
Hi,
I want to check if variable has blank or 0 (zero).
for example,
double X = 0 or null;
if x is blank (means null) or 0 (zero)
{
// blank or zero
}
else
{
//has value
}
All-Star
31362 Points
7055 Posts
Re: How to check if double variable is blank (null) or 0 (zero).
Sep 06, 2017 10:11 AM|kaushalparik27|LINK
Double or double is a value type and you cannot directly assign null to it. That also means it cannot have a null value. To allow this, you have to define it as nullable. For more read you should refer to Nullable Types (C# Programming Guide) | Microsoft Docs
To answer your question, I suggest you use nullable double type for X and then you will be able to check for null. Here is one example:
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you