Quick question here about short-circuiting statements in C#. With an if statement like this:
if (MyObject.MyArray.Count == 0 || MyObject.MyArray[0].SomeValue == 0)
{
//....
}
Is it guaranteed that evaluation will stop after the "MyArray.Count" portion, provided that portion is true? Otherwise I'll get a null exception in the second part.
Yes, this is guaranteed.
C# Language Specification - 7.11 Conditional logical operators:
The
&&
and||
operators are called the conditional logical operators. They are also called the "short-circuiting" logical operators.
Therefore they will support logical short-circuiting by definition - you can rely on this behavior.
Now it is important to make a distinction between a conditional operator and a logical operator:
|
and a logical AND is &
.