Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

^=: practical reference

^=: practical reference: ^= combines XOR with assignment, toggling the selected bits.

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

Syntax

left ^= right

^= combines XOR with assignment, toggling the selected bits.

Use it for an explicit reversible toggle with a mask.

Repeating the same mask restores the value, but concurrent use is not atomic.

The result is converted back to the type of the left operand.

The complete program actually uses ^=; its exact expected stdout is 6.

Examples

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

var value = 5; value ^= 3; Console.WriteLine(value);

Result

6

The complete program actually uses `^=`; its exact expected stdout is `6`.

Sources