> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Address-of

The `&` operator in C# is a binary operator that performs a bitwise logical AND operation on integral numeric types and enumeration types, and an unconditional logical AND operation on boolean types.

## Bitwise AND (Integral Types)

When applied to integral numeric types (`int`, `uint`, `long`, `ulong`, `nint`, `nuint`), the `&` operator evaluates the binary representation of both operands and compares them bit by bit. The resulting bit is set to `1` if and only if the corresponding bits in both operands are `1`. Otherwise, the resulting bit is set to `0`.

```csharp theme={"dark"}
uint a = 0b_1100_1001; // Decimal: 201
uint b = 0b_1010_1100; // Decimal: 172
uint c = a & b;        // Result:  0b_1000_1000 (Decimal: 136)
```

### Implicit Numeric Promotion

C# does not define built-in `&` operators that return smaller integral types (`byte`, `sbyte`, `short`, `ushort`, `char`). When the `&` operator is applied to these types, C# applies implicit numeric promotion. The operands are automatically promoted to `int`, and the result of the operation is an `int`.

If one operand is `uint` and the other is a signed integral type (`sbyte`, `short`, or `int`), both operands are promoted to `long`, and the result is a `long`.

```csharp theme={"dark"}
byte x = 0b_1010;
byte y = 0b_1100;

// byte z = x & y; // Compiler error: Cannot implicitly convert type 'int' to 'byte'
int result = x & y; 
byte explicitResult = (byte)(x & y); // Requires an explicit cast

uint unsignedInt = 5;
int signedInt = -1;
long mixedResult = unsignedInt & signedInt; // Promoted to long
```

## Bitwise AND (Enumeration Types)

The `&` operator is fully supported for `enum` types. The operation is performed on the underlying integral type of the enumeration. This is mechanically essential for evaluating bitmask enumerations, typically decorated with the `[Flags]` attribute.

```csharp theme={"dark"}
[Flags]
public enum FileAccess
{
    None = 0,
    Read = 1,
    Write = 2,
    Execute = 4
}

FileAccess permissions = FileAccess.Read | FileAccess.Write;
FileAccess check = permissions & FileAccess.Read; // Evaluates to FileAccess.Read
```

## Unconditional Logical AND (Boolean Types)

When applied to `bool` operands, the `&` operator computes the logical AND. The result is `true` if both operands evaluate to `true`; otherwise, the result is `false`.

Unlike the conditional logical AND operator (`&&`), the `&` operator is **non-short-circuiting**. It strictly evaluates both the left-hand side (LHS) and right-hand side (RHS) expressions, regardless of the outcome of the LHS evaluation.

```csharp theme={"dark"}
bool EvaluateRHS()
{
    Console.WriteLine("RHS Evaluated");
    return true;
}

// The LHS is false, but EvaluateRHS() is still invoked.
bool result = false & EvaluateRHS(); 
```

## Nullable Boolean Logical AND (`bool?`)

When applied to nullable boolean (`bool?`) operands, the `&` operator implements three-valued logic. The evaluation rules are:

* Returns `true` if both operands are `true`.
* Returns `false` if *either* operand is `false`, even if the other operand is `null`.
* Returns `null` otherwise (i.e., if one operand is `true` and the other is `null`, or if both are `null`).

The compiler requires explicit typing for `null` literals in these expressions to resolve the operator overload.

```csharp theme={"dark"}
bool? nullBool = null;

bool? a = true & nullBool;     // Evaluates to null
bool? b = false & nullBool;    // Evaluates to false
bool? c = nullBool & nullBool; // Evaluates to null

// Alternatively, using explicit casts:
bool? d = true & (bool?)null;  // Evaluates to null
```

## Compound Assignment

The `&` operator supports compound assignment via the `&=` operator. An expression using `&=` evaluates the bitwise or logical AND of the operands and assigns the result to the left operand.

```csharp theme={"dark"}
int x = 0b_1111;
x &= 0b_1010; // x is now 0b_1010

bool flag = true;
flag &= false; // flag is now false
```

## Operator Overloading

User-defined types (classes and structs) can overload the `&` operator to define custom evaluation logic. When a user-defined type overloads the `&` operator, the `&=` operator is implicitly overloaded as well.

```csharp theme={"dark"}
public struct CustomType
{
    public int Value { get; }

    public CustomType(int value) => Value = value;

    public static CustomType operator &(CustomType left, CustomType right)
    {
        return new CustomType(left.Value & right.Value);
    }
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
