Is there any benefit to use `Array<MyType>.Index` instead of just `Int`

which one should I be using in my code?

Usually for concrete types, it doesn't matter. It might affect some type checking performance, which is usually negligible.

That said, I tend to use Index in some cases, where I might replace Array with other collections later.

2 Likes

with just Index, I got compile error:

Cannot find type 'Index' in scope

Only Array<MyType>.Index work. Am I missing something?

No, I meant to use its full form. Bare Index only works from within an extension of a collection (which is where I mostly place collection-related algorithms anyway).

2 Likes

For me I prefer using Index because it denotes intent and purpose along with making it more generic which often things I am writing around an Array can be extended to other collections and I am just starting with an Array for simplicity.

1 Like