&& Operator (C# Reference)

The conditional logical AND operator &&, also known as the "short-circuiting" logical AND operator, computes the logical AND of its bool operands. The result of x && y is true if both x and y evaluate to true. Otherwise, the result is false. If the first operand evaluates to false, the second operand is not evaluated and the result of operation is false. The following example demonstrates that behavior:

bool SecondOperand()
{
    Console.WriteLine("Second operand is evaluated.");
    return true;
}

bool a = false && SecondOperand();
Console.WriteLine(a);
// Output:
// False

bool b = true && SecondOperand();
Console.WriteLine(b);
// Output:
// Second operand is evaluated.
// True

The logical AND operator & also computes the logical AND of its bool operands, but always evaluates both operands.

Operator overloadability

A user-defined type cannot overload the conditional logical AND operator. However, if a user-defined type overloads the logical AND, true, and false operators in a certain way, the && operation can be evaluated for the operands of that type. For more information, see the User-defined conditional logical operators section of the C# language specification.

C# language specification

For more information, see the Conditional logical operators section of the C# language specification.

See also