Imagine this case where I have an object that I need to check a property. However, the object can currently have a null value.
How can I check these two conditions in a single "if" condition?
Currently, I have to do something like this:
if (myObject != null) { if (myObject.Id != pId) { myObject.Id = pId; myObject.Order = pOrder; } }
I would like something like this:
if (myObject != null && myObject.Id != pId)
I want to evaluate the second condition only if the first was true.
&&is a short-circuiting logic test – it only evaluates the right-hand-side if the left-hand-side is true. Contrast toa & b, which always evaluates both sides (and when used with integral types instead ofbool, does a bitwise "and").