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 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.
int, uint, long, ulong, byte, sbyte, short, ushort), the ^ operator computes the bitwise exclusive OR of the corresponding bits of the two operands.
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.
^ prefix into a call to the System.Index constructor, passing the integer value and a boolean indicating that the index is from the end.
Master C# with Deep Grasping Methodology!Learn More





