We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

C# order of evaluation

josgood
josgood asked
on
Medium Priority
852 Views
Last Modified: 2012-05-06
In C++, two things are true about an expression such as
   (a == b) || (c == d)

1)  The order of evaluation is not guaranteed, (c == d) could be evaluated before (a == b)
     (Section 5, paragraph 4 of the standard. "Except where noted, the order of evaluation (...words deleted...) is unspecified)
2)  If either (a == b) or (c == d) is true, then expression evaluation is shortcut and the other comparison is not evaluated.

Section 8.5 of the ECMA-366 C# standard says "Except for the assignment operators, all binary operators are left-associative"

1)  It looks to me as though (a == b) will always be evaluated first in C#.  Am I missing anything?
2)  If (a == b) is true, will C# evaluate (c == d)?
Comment
Watch Question

Technical Manager
Commented:
1)  It looks to me as though (a == b) will always be evaluated first in C#.  Am I missing anything?
yes you are correct a==b will be evaluated first

2)  If (a == b) is true, will C# evaluate (c == d)?
if a==b will be true and an OR condition is there then c==d will NOT be evaluated

it saves processing time and will only be evaluated when a==b is False

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2007

Author

Commented:
Thank you.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.