Single-dimensional arrays
Let’s start with the simplest variant of arrays, namely single-dimensional ones. Such an array stores a collection of items of the same type, which are accessible by an index. It is important to remember that indices of elements within arrays in C# are zero-based. This means that the first element has an index equal to 0
, while the last one has an index equal to the length of the array minus one.
Imagine a single-dimensional array
If you want to better imagine a single-dimensional array, take your eyes off this book for a moment and look at the chest of drawers or wardrobe in your room. A standard chest of drawers consists of several drawers and a single-dimensional array looks similar. It also has several elements (as drawers), which are accessible via the index. You cannot change the size of the array in the same way as you cannot change the number of drawers since the furniture is prepared. An array has one significant advantage over a chest...