Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

|=: practical reference

|=: practical reference: |= combines OR with assignment to the left location.

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

Syntax

left |= right

|= combines OR with assignment to the left location.

Use it to add bits or flags without clearing those already present.

It does not validate that the resulting enum combination is defined.

The left side is evaluated once and the result is converted back to its type.

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

Examples

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

var value = 4; value |= 1; Console.WriteLine(value);

Result

5

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

Sources