1

What is the reasoning behind the c# index type to index based on 1 when it's from the end?

Index idx2 = ^3; // 3rd item from end

So the above is the 3th element and not the 4th. It's seems rather inconsistent to have it 1 based.

EDIT: The operator ^ for indexes is a new C# 8 Feature

clankill3r
  • 9,146
  • 20
  • 70
  • 126
  • 1
    [Hm](https://www.c-sharpcorner.com/article/c-sharp-index-type2/) _Index idx1 = 2; // 3rd item. Array index starts at 0. Index idx2 = ^3; // 3rd item from end_ So: __end__ is not the last element but the spot __after the last__ !! – TaW Sep 29 '19 at 15:59
  • because it makes sense, we can say the last one and get the last element by `A[^1]` – MD TAREQ HASSAN Sep 29 '19 at 16:07
  • @HassanTareq But the first one is `A[0]`. – GSerg Sep 29 '19 at 16:10
  • @GSerg array index is zero-based because compiler needs one less operation than one-based (i.e. row-major). So, `A[0]` and `A[^1]` are ok (in my opinion) – MD TAREQ HASSAN Sep 30 '19 at 09:46

0 Answers0