Possible Duplicate:
Will all methods in a logical expressions be executed?
Let me explain: let’s say we have theese two codes:
foreach(Object o in Objs)
if(o is Class1 || o is Class2)
DoSomething();
__
foreach(Object o in Objs)
if(o is Class1)
DoSomething();
else if(o is Class2)
DoSomething();
Now, of course an OR is better in this case, but my question is different and just out of curiosity: when in the first case o is of type Class1, does the compiler stop and run the code or it checks what comes next anyway?
It would do that in the second case.
||is short-circuiting, which means: if the first argument returnstrue, the second argument is not evaluated. In this way, yes it is broadly equivalent to your second example, but more terse.