Individual elements in a string or an array can be accessed via the bracketed
expression. The norm for accessing elements from last is usually in the format of foo[ub - i]
where ub
is the upper bound and i
is an index. This expression however can be simplified and rewritten as foo[^i]
.
var lastElement = array[array.Length - 1];
var lastElement = array[^1];