If objects contains null or empty then how to validate or check the condition for the same?
How to bool check whether object obj is null
or Empty
I've code as follows:
class Program
{
static void Main(string[] args)
{
object obj = null;
double d = Convert.ToDouble(string.IsNullOrEmpty(obj.ToString()) ? 0.0 : obj);
Console.WriteLine(d.ToString());
}
}
With this code i'm getting NullReference Exception
as Object reference not set to an instance of an object.
Pls help.
Here I'm not getting....
How to validate whether that object is null
or Empty
without converting into .ToString() ??
Is there an approach to check the same??
ToString()
on an object you know isnull
, and therefore generatesNullReferenceException
? – Monauralobject
is empty?? – Brott