Some of my knowledge about the topic is as following. If consecutive operators in an expression have the same precedence, a rule called associativity is used to decide the order in which those operators are evaluated. Further, left-associative operators of the same precedence are evaluated in order from left to right.
What I don't understand is why the following code doesn't throw exception.
if (
object == null ||
object.Flag &&
object.Status == object2.Status
)
What if object is null
? In this case, doesn't the call of object.Status
throws exception because of high precedence of ==
over &&
, likewise &&
over ||
? I mean,
if (
(object == null) ||
(object.Flag &&
(object.Status == object2.Status))
)
The call order,
object.Status == object2.Status
object.Flag
object == null
What point do I overlook?
Aucun commentaire:
Enregistrer un commentaire