...

/

Take Method with Ranges

Take Method with Ranges

Learn how to select a slice of elements of a collection.

What are indices and ranges?

Starting from C# version 8.0, we have two new operators: the index from the end operator (^) and the range operator (..).

With the index from the end operator (^), we can access elements from the end of arrays—for example, the last element of an array would be myArray[^1]. Before, we had to use the length of the array to access elements from the end with myArray[myArray.Length - 1].

On the other hand, with the range operator (..) we can ...