Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

&=: practical reference

&=: practical reference: &= combines bitwise or logical AND with assignment to the left operand.

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

Syntax

left &= right

&= combines bitwise or logical AND with assignment to the left operand.

Use it to clear bits with a mask or to accumulate flags.

The Boolean right side always runs, while the left location is evaluated once.

Compound-assignment rules convert the result back to the left-side type.

The complete program actually uses &=; its exact expected stdout is 2.

Examples

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

var value = 6; value &= 3; Console.WriteLine(value);

Result

2

The complete program actually uses `&=`; its exact expected stdout is `2`.

Sources