0

I know that the && operator and || operators are short-circuited in c#. But are the &= operators and |= operators as well? Suppose I have a statement:

bool a = doSomething();
a &= doNext();

Is this guaranteed to be equivalent to:

bool a = doSomething();
if(!a)
  a = doNext();
arviman
  • 5,087
  • 41
  • 48

2 Answers2

0

I imagine that would actually be equivalent to:

a = a & doNext()

Google for bitwise operations to see more.

Luke
  • 560
  • 6
  • 26
0

Yes it does http://msdn.microsoft.com/en-us/library/e669ax02.aspx and no it is not equal to &&. It is a short version of & operator plus assigment. doNext method would be called and executed for any "a" value.

Zed
  • 1
  • 3
    So, by "Yes it does", you mean "No it does not short-circuit"? –  Oct 07 '14 at 09:48
  • I missunderstood your question a little. I thought short-circuit means &= instead of = ... & ... . Sorry – Zed Oct 07 '14 at 09:53