Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

|: practical reference

|: practical reference: | performs bitwise OR on integers or non-short-circuit logical OR on bool values.

Version: C# language; verified against C# 14 reference

Syntax

left | right

| performs bitwise OR on integers or non-short-circuit logical OR on bool values.

Use it to set flags or when both Boolean conditions must execute.

With bool, the right side always executes, unlike ||.

Inconsistent enum flags can produce an unnamed combination.

The complete program actually uses |; its exact expected stdout is 5.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

Console.WriteLine(4 | 1);

Result

5

The complete program actually uses `|`; its exact expected stdout is `5`.

Sources