Back to Writing
NOTEScsharpcsharp-8indexrangeunity

C# 8.0 - Index, Range, and the Caret (^) Operator

February 15, 2021Updated Feb 17, 2026

![](

하지만0izvUs-fm1_Y1Jgg.xhmww0kHYgKQpmglt6Raeh-oelt_vyaDAQZuqQITaSog.PNG.cdw0424/csharp.png?type=w966)

Since Unity started supporting C# 8.0 from version 2020.2, I've been reviewing the C# 8.0 documentation and discovered some very convenient features — namely the new indexing methods and slicing approach.

The traditional indexing method was quite cumbersome when accessing elements from the end in reverse order, but now you just need the ^ (caret) operator and System.Index.

using System.Index;

int[] Arr = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

Arr[1]  // is 2
Arr[^1] // is 10

Arr[9]   // is 10
Arr[^10] // is 1

An important note: when using ^, counting starts from 1, not 0. Be careful.

Next, Range uses the Range object with the .. (dot-dot) operator.

Let me illustrate with examples:

using System.Range;
using System.Index;

int[] Arr = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

// Range of 1st, 2nd, 3rd elements of the Arr array
print(Arr[0..3]); // Result: 1, 2, 3

// You can also use the caret operator together
print(Arr[^0..^3]); // Result: 10, 9, 8

Finally, to use C# 8.0 in Unity, you need to install and configure .NET Core 3.0 or higher.

What's new in C# 8.0 - C# Guide