You get a null reference because you are running obj.ToString() , which returns the return value of the obj ToString () method. The problem is that in the previous line you set obj to null to get a reference to the object not ... error
To do the work with the code, you need to do:
//This will check if it a null and then it will return 0.0 otherwise it will return your obj. double d = Convert.ToDouble(obj ?? 0.0);
Now your code, as now, will always be 0.0
Without zero coalescence: (??)
double d = Convert.ToDouble(obj ? 0.0 : obj);
EDIT
If I understand correctly from the comments you want to know if the object is empty or empty. You can do this by setting the string first, rather than calling the ToString method, which does something completely different:
string objString = (obj as string); double d = Convert.ToDouble(string.IsNullOrEmpty(objString) ? "0.0" : objString);
TBohnen.jnr
source share