TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
^ operator in C# serves two distinct syntactic functions 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)
As a binary operator,^ evaluates the exclusive OR of its operands. It is supported for boolean types and integral numeric types.
Boolean Operands:
When applied to bool operands, ^ computes the logical exclusive OR. It evaluates to true if and only if exactly one operand evaluates to true. If both operands evaluate to the same value, the result is false. Unlike the conditional logical operators (&&, ||), the ^ operator always evaluates both operands; it does not short-circuit.
int, uint, long, ulong, byte, etc.), ^ computes the bitwise exclusive OR. It compares the binary representation of both operands bit by bit. The resulting bit is set to 1 if the corresponding bits in the operands are different, and 0 if they are identical.
^ operator can be combined with the assignment operator to form ^=. This applies the XOR operation to the left and right operands and assigns the resulting value to the left-hand variable.
2. Index from End Operator (C# 8.0+)
As a unary prefix operator,^ instantiates a System.Index struct representing an offset relative to the end of a sequence (such as an array, Span<T>, or string).
The index ^n is mathematically translated by the compiler to sequence.Length - n. Because C# uses zero-based indexing from the start, the index ^0 equals the sequence length (which throws an IndexOutOfRangeException if used for direct element access), and ^1 represents the final element in the sequence.
Master C# with Deep Grasping Methodology!Learn More





