As the others stated bool?
is not equal to bool
. bool?
can also be null
, see Nullable<t>
(msdn).
If you know what the null
state wants to imply, you easily can use the ?? - null-coalescing operator (msdn) to convert your bool?
to bool
without any side effects (Exception
).
Example:
//Let′s say "chkDisplay.IsChecked = null" has the same meaning as "chkDisplay.IsChecked = false" for you
//Let "check" be the value of "chkDisplay.IsChecked", unless "chkDisplay.IsChecked" is null, in which case "check = false"
bool check = chkDisplay.IsChecked ?? false;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…