Skip to content

C# Feature - Index operator

The index operator ^ addresses elements from the end of an array, span, or indexer-enabled type.

C# 8.0 (2019)

int last = values[values.Length - 1];
int last = values[^1];
char lastLetter = word[^1];
char secondLastLetter = word[^2];
  • ^1 means the last element, not one past the end.
  • Use it when indexing from the end improves readability over manual arithmetic.
  • C# 8 introduced Index and the ^ operator for end-based indexing.