The ^
operator is used for indexing from the end of an array or collection. Specifically, ^1
represents the last element, ^2
represents the second-to-last element,
void Display(int[] s) => Console.WriteLine(string.Join(" ", s));
int[] xs = [0, 0, 0];
Display(xs);
ref int element = ref xs[0];
element = 1;
Display(xs);
element = ref xs[^1];
element = 3;
Display(xs);
// Output:
// 0 0 0
// 1 0 0
// 1 0 3
Refereneces:https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/declarations#reference-variables