查看线程标题.我可以安全地做这样的事情,而不用担心NullReferenceException,或者不能保证那些布尔表达式将从左到右进行评估?
// can this throw an NRE? if (obj == null || obj.property == value) { // do something }
解决方法
他们将从左到右进行评估,保证.所以是的,它的安全.
The conditional-OR operator (||)
performs a logical-OR of its bool
operands,but only evaluates its
second operand if necessary.
http://msdn.microsoft.com/en-us/library/6373h346%28VS.71%29.aspx