I'm a bit puzzled by this compiler warning, which I get on this line in my DataGridView program:
I think the message pertains to the member Value being potentially null. Although I'm not quite sure because of the way the IDE places the squiggly line:
suggesting the issue is with the ToString() method?
Anyway I honestly don't understand why the compiler needs to fuss over something like this. In the unlikely event that I forgot to fill a grid cell, I would be more than happy to get a runtime exception.
But putting it in a try\catch does not get rid of the error, nor does explicitly testing for null.
It's not a problem, I can choose to ignore or suppress the warning, but I don't like either of these options.
I want this to compile cleanly but can't figure out how. I vaguely remember something called GetValueOrDefault() but I could not make that work here.
Also I can't decide whether the compiler is helpful or pedantic (and is there even a difference in a case like this).
Any ideas?
if (grid.Rows.Cells[COLUMN_FILE].Value.ToString().ToUpper().StartsWith(jumper))
I think the message pertains to the member Value being potentially null. Although I'm not quite sure because of the way the IDE places the squiggly line:
suggesting the issue is with the ToString() method?
Anyway I honestly don't understand why the compiler needs to fuss over something like this. In the unlikely event that I forgot to fill a grid cell, I would be more than happy to get a runtime exception.
But putting it in a try\catch does not get rid of the error, nor does explicitly testing for null.
It's not a problem, I can choose to ignore or suppress the warning, but I don't like either of these options.
I want this to compile cleanly but can't figure out how. I vaguely remember something called GetValueOrDefault() but I could not make that work here.
Also I can't decide whether the compiler is helpful or pedantic (and is there even a difference in a case like this).
Any ideas?
Attachments
Last edited: