Search code examples
c#operatorsshort-circuiting

Does c# short-circuit the &= and |= operator


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();

Solution

  • I imagine that would actually be equivalent to:

    a = a & doNext()
    

    Google for bitwise operations to see more.