is there a difference between:
if (myObject != null && myObject.someint == 0)
{
// do something
}
and
if (myObject != null)
{
if (myObject.someint == 0)
{
// do something
}
}
I always thought that it evaluates the first condition, and if false, it skips evaluation of the second. However I got an error in run-time of null-reference. myObject was null, and it was trying to check myObject.someint
The object can be modified externally, is it a case when it checked the first condition the object existed, but when it went on to the next condition something has killed the reference in myObject?
if its the latter, any way to avoid (b/c in my mind both of the above ways of doing the if check are the same). only possible i can imagine is try/catch
It must be the later condition since the && short circuits on
false. Use