> ## 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# Index from End

The `^` operator in C# serves two distinct syntactic purposes depending on its context: as a binary Logical/Bitwise Exclusive OR (XOR) operator, and as a unary Index from End operator.

## 1. Logical and Bitwise Exclusive OR (XOR) Operator

When used as a binary operator between two operands, `^` computes the exclusive OR. It evaluates to `true` (or `1`) if and only if exactly one of the operands is `true` (or `1`). If both operands are the same, it evaluates to `false` (or `0`).

**Logical XOR (Boolean Operands)**
For `bool` operands, the `^` operator computes the logical exclusive OR. Unlike the conditional logical operators (`&&`, `||`), the `^` operator always evaluates both operands; it does not short-circuit.

```csharp theme={"dark"}
bool a = true ^ false;  // Evaluates to true
bool b = true ^ true;   // Evaluates to false
bool c = false ^ false; // Evaluates to false
```

**Bitwise XOR (Integral Operands)**
For integral numeric types (`int`, `uint`, `long`, `ulong`, `byte`, `sbyte`, `short`, `ushort`), the `^` operator computes the bitwise exclusive OR of the corresponding bits of the two operands.

```csharp theme={"dark"}
int x = 5;      // Binary: 0101
int y = 3;      // Binary: 0011
int z = x ^ y;  // Binary: 0110 (Evaluates to 6)
```

## 2. Index from End Operator (C# 8.0+)

When used as a unary prefix operator, `^` instantiates a `System.Index` struct representing an offset from the end of a sequence (such as an array, `Span<T>`, or string).

The index `^n` translates to the sequence's `Length - n`. Therefore, `^1` points to the last element in the sequence. `^0` points to the sequence length itself, which will throw an `IndexOutOfRangeException` if used for direct element access, but is valid when used as the upper bound in a Range (`..`) expression.

```csharp theme={"dark"}
int[] sequence = { 10, 20, 30, 40, 50 };

// Element access
int last = sequence[^1];        // Evaluates to 50 (sequence.Length - 1)
int secondToLast = sequence[^2]; // Evaluates to 40 (sequence.Length - 2)

// Range expression usage
int[] subSequence = sequence[..^1]; // Evaluates to { 10, 20, 30, 40 }
```

**Underlying Type Evaluation**
The compiler translates the `^` prefix into a call to the `System.Index` constructor, passing the integer value and a boolean indicating that the index is from the end.

```csharp theme={"dark"}
Index idx = ^3; 
// Equivalent to: Index idx = new Index(3, fromEnd: true);
```

<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>
