Does the compiler continue to evaluate the expression, where should everything be true if the first is false?

I am sure that this question has probably already been answered, so I apologize, but I could not find the correct search conditions to find the answer.

Given the following code example, is it executing db.GetRecords().Any()?

string s = "Z";
bool x = s.IndexOfAny(new[] { 'A', 'B' }) > 0 &&
         db.GetRecords().Any();
+3
source share
6 answers

No. As well &&, the short circuit rating is|| evaluated . This means that it returns false if it is false, but returns true if it is true and will not evaluate in any of these cases.a && baa || bab

- , & |.

+8

. && ( , , - false).

|| , , true.

+2

, # . .

, NON-SHORT-CIRCUIT, .

tring s = "Z";
bool x = s.IndexOfAny(new[] { 'A', 'B' }) > 0 &
         db.GetRecords().Any();

.

+2

, # -AND (&&), - , , , .

&& & & ( #)

-AND (& &) -AND bool, .

-AND, -OR (||) , , . , false || .

|| ( #)

, #, , , VB.NET, AND (And, AndAlso) OR (Or, OrElse). And, , , , false , AndAlso , . Or OrElse, Or , OrElse .

(Visual Basic)

.

AndAlso (Visual Basic)

.

(Visual Basic)

.

OrElse (Visual Basic)

.

, , , . #, .

+2

:

if(ob && ob.somefunc()) { ... }

, , .

+1

Source: https://habr.com/ru/post/1770928/


All Articles