Selection from left to right

In C #, is it guaranteed that expressions are evaluated from left to right?

For example:

myClass = GetClass();  
if (myClass == null || myClass.Property > 0)  
    continue;

Are there any languages ​​that don't match?

+5
source share
9 answers

In fact, you are referring to a language function called "logical expression short circuit":

This means the following: when the result of a logical expression can no longer change, for example. when it is clear that the expression will be evaluated as β€œtrue” or β€œfalse”, regardless of whether the remaining parts of the expression will be evaluated.

, #, Java JavaScript , ( ).

, MyClass null:

  • MyClass == null false
  • "", ,
  • myClass.Property > 0

MyClass null:

  • MyClass == null true
  • "", ,
  • , .

, . VB , "myClass.Property > 0" , MyClass ( "Nothing" VB).

+14

7.11 # 3.0:

x || y x | y, , y , x .

, .

- . VB.NET OrElse AndAlso, , Or And .

+5

:

-

sprintf (buf, "% s% s", func1 (& var), func2 (& var));

var, ( C, , ), func1() func2() ( , ( ) .

+2
0

, ?

100%, , # ( , , .net). , .

# (& & &). , , .

0

/ , Ada, Visual Basic Pascal, . , " " " " Ada.

0

Python or and.

0

Java Haskell && || .

, Haskell ( , ), Java # .

0

- , , - . , C (ANSI, ISO, C99) . NULL ... , . - .

0

All Articles