Short circuiting statement evaluation — is this guaranteed? [C#]

后端 未结 6 2253
不思量自难忘°
不思量自难忘° 2020-12-10 11:53

Quick question here about short-circuiting statements in C#. With an if statement like this:

if (MyObject.MyArray.Count == 0 || MyObject.MyArray[0].SomeValu         


        
6条回答
  •  攒了一身酷
    2020-12-10 12:41

    Yes, it is guaranteed.

    http://msdn.microsoft.com/en-us/library/6373h346%28v=VS.80%29.aspx

    The conditional-OR operator (||) performs a logical-OR of its bool operands, but only evaluates its second operand if necessary.

提交回复
热议问题