I’ve come across a curious problem with the following code. It compiles fine although Resharper highlights the code segment (autorefresh == null), notifying me Expression is always false
bool? autorefresh = Properties.Settings.Default.autorefresh;
autorefresh = (autorefresh == null) ? false : autorefresh;
Enabled = (bool)autorefresh;
Any ideas how better to get around this problem?
Edit 07/02/2012 16:52
Properties.Settings.Default.autorefresh
The above is a bool, not a string.
I think what you want is:
In light of your comments, it appears you were unneccessarily assigning the value of
autorefreshto aNullable<bool>. In terms of safeguarding the data, theSettingswill return you the default value for that type if it is invalid or missing (which would befalseforboolean‘s). Therefore, your code should simply be: