I have come across a piece of code that I can't wrap my head around:
public void Connect()
{
if (!(!string.IsNullOrEmpty(_vpnConnectionName) & !string.IsNullOrEmpty(_ipToPing)))
{
return;
}
GetConnected();
}
I've researched the single ampersand on SO and elsewhere, and found it is a Bitwise AND operand. However the explanations all revolve around integers.
I can understand the applicability of bitwise operations on integers, but how are they applicable to booleans?
It is a logical operator on bools that evaluates both sides regardless of the value of the left side.
For bool, & isn't a bitwise AND operator - it's the non-short-circuiting logical AND operator - it always evaluates both arguments - as opposed to the "usual" && operator that only evaluates its second argument if its first argument is true.
(Realised that it may not be obvious, that the first & above is linked to the actual documentation)
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