H
Herfried K. Wagner [MVP]
Michael C said:At least for me an array index is more than a position only. In
addition, I consider it a numeric /key/ used to define a mapping between
numeric keys and values (f(x) = y, x in [a, ..., b]).
An array is meant to be the simplest most efficient list you can have, a
contiguous block of memory.
I'd consider it a low-level implementation detail that an array is stored as
a contiguous block of memory.
If you want to add, insert, remove items or store a key then you don't
want an array, you want a collection of some sort.
Although that's true, I didn't say that I prefer insertion of values into
arrays.
It is a lot clearer in C# than VB. In C# you cannot modify your array
making it pretty obvious to the programmer it is a fixed block of memory.
If you want a fixed block that does not change then use an array, if you
need to change it then use a collection.
The fixed block semantics are IMO an implementation detail which is
irrelevant for programming languages which do not provide pointer access to
the array data.
What do you mean there?
Arrays are so limited in functionality making them a bad choice in most
cases. Imagine a method returning an array of data. If you want to
manipulate the data (removing and inserting items), you'll either have to
create a new array and copy the items into the new array or copy them to
another data structure. This approach is not very efficient and requires
duplication of values or references.