_callReportCode = reader["Call Report Code"].ToString();
I am attempting to handle the possibility for the object I am calling ToString on to be NULL. I am going to be using the above statement with several variables and I dont want to make an individual try/catch for each one... what is the best way to do null checking for strings.
Other datatypes ive been doing this:
int.TryParse(reader["Account Number"].ToString(), out _accountNumber);
In this code "reader" refers to a SqlDataReader but thats not really important for this question.
reader['blah']
isNull
before calling.ToString()
. Exceptions should never be part of your normal execution flow, they're expensive and not designed to be used in that way (eg too easy to catch the wrong thing if you don't think carefully) – Basic Apr 5 '13 at 13:44