|| Operator (C# Reference)

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

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

bool a = true || SecondOperand();
Console.WriteLine(a);
// Output:
// True

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

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

Operator overloadability

A user-defined type cannot overload the conditional logical OR operator. However, if a user-defined type overloads the logical OR, 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