Search code examples
c#bit-manipulationbitwise-and

How does Bitwise AND interact with boolean values?


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?


Solution

  • It is a logical operator on bools that evaluates both sides regardless of the value of the left side.