I have a method that will receive a string
, but before I can work with it, I have to convert it to int
. Sometimes it can be null
and I ha
Personally I'd go for the corrected version of your bosses - possibly with even more checks on it - if the string's empty, yours will, as you say throw an exception, as "" isn't a well formatted number and ?? only checks for null.
Something like:
public int doSomeWork(string value) {
int someValue = 0;
if (!string.IsNullOrEmpty(value)) {
Int.TryParse(value, out someValue);
}
}
Which resolves the issue where value equals "Forty Two".