&= Operator (C# Reference)

The AND assignment operator.

An expression using the &= operator, such as

x &= y

is equivalent to

x = x & y

except that x is only evaluated once.

For integer operands, the & operator computes the bitwise logical AND of its operands; for bool operands, it computes the logical AND of its operands.

The following example demonstrates the usage of the &= operator:

byte a = 0b_1111_1000;
a &= 0b_1001_1111;
Console.WriteLine(Convert.ToString(a, toBase: 2));
// Output:
// 10011000

bool b = true;
b &= false;
// Output:
// False

Operator overloadability

If a user-defined type overloads the & operator, the AND assignment operator &= is implicitly overloaded. A user-defined type cannot explicitly overload the AND assignment operator.

C# language specification

For more information, see the Compound assignment section of the C# language specification.

See also