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#?
Is there anything to achieve something like "&&=" in C#?
Well, you can write
a = a && getBool();
instead... I can't think of many situations where I'd actually want to do anything different, to be honest. Even the above is pretty rare, IME.
There's no compound assignment operator defined for &&
, ||
or ??
(which are the obvious "short-circuiting" operators). See section 7.17 of the C# 4 spec for the full list of compound assignment operators, and section 7.17.2 for more details about what exactly compound assignment does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With