Depends on how you want someNullableBool
to be interpreted if it's null.
If you want null
to be treated like either true
or false
, you can say (someNullableBool ?? valueIfNull)
to treat it like one or the other.
If null
has to be handled specially, then you'll need to check someNullableBool.HasValue
and handle the case where it's null. Once you've done that, the case for true
and false
can be handled as above.
If the value should never be null, ideally it shouldn't be a nullable in the first place. :P But if that's out of your control, you might want to cast to bool
or use the nullable's Value
property to make that expectation explicit, and to fail if ever it doesn't hold.