Possible Duplicate:
Why are there no ||= or &&= operators?
By pure accident I found out today that
a &= GetBool();
is NOT the same as
a = a && GetBool();
I must have misunderstood that for years. In the first Example, “GetBool()” is executed even if “a” is false. In the second, it isn’t.
Is there anything to achieve something like “&&=” in C#?
From the documentation:
I would say, to avoid evaluation of y when not necessary, use
and to avoid evaluation of x twice (whatever this means), use
You can’t combine both.
Micro-optimized (at least for a theoretical case), it would be:
You don’t need to do anything if x is already
false.