IndexOutOfRangeException
CS-W1042Languages like Python allow you to access elements from the last by specifying negative indices. However, this does not work in C# and will result in an IndexOutOfRangeException
. In order to access elements from the last, consider prefixing the indices with ^
operator.
var last = arr[-1];
var last = arr[^1];