Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

&: practical reference

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

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

Syntax

left & right

& performs bitwise AND on integers or non-short-circuit logical AND on bool values.

Use it for bit masks or when both Boolean operands must be evaluated.

With bool, the right operand always runs, unlike &&.

Signed width and numeric promotions determine the bits of the result.

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

Examples

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

Console.WriteLine(6 & 3);

Result

2

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

Sources