I’m sure this question has probably been answered before, so I apologize, but I wasn’t able to find the proper search terms to find the answer.
Given the following code example, does db.GetRecords().Any() get executed?
string s = "Z";
bool x = s.IndexOfAny(new[] { 'A', 'B' }) > 0 &&
db.GetRecords().Any();
No. Both
&&and||are evaluated by short-circuit evaluation. This means thata && breturns false ifais false anda || breturns true ifais true and it will not evaluatebin either of these cases.If for some reason you do not want short-circuit evaluation you can use the bitwise operators
&and|.