我基本上有以下内容:
int? myVal = null; myVal |= 1; bool stillNull = myVal == null; //returns true
为什么这样做?我对按位运算符/操作数行为的理解并不是非常强大,我找不到在这种情况下不会将其视为简单赋值的原因.
解决方法
从
MSDN开始:
The predefined unary and binary operators and any user-defined operators that exist for value types may also be used by nullable types. These operators produce a null value if the operands are null; otherwise,the operator uses the contained value to calculate the result.