Slices and Other Array Features

In this lesson, we will discuss slices and other array features like array.length, .dup etc.

We have seen earlier in this chapter how elements are grouped as a collection in an array. This lesson further elaborates on that concept by explaining the features of the arrays.

Before going any further, here are a few brief definitions of some terms that happen to be close in meaning:

  • Array: the general concept of a group of elements that are located side by side and are accessed by indexes

  • Fixed-length array (static array): an array with a fixed number of elements; this type of array owns its elements and doesn’t allow one to change the length of the array

  • Dynamic array: an array that can gain or lose elements; this type of array provides access to elements that are owned by the D runtime environment

  • Slice: another name for the dynamic array

When we use slice, it will mean a dynamic array. On the contrary, when we use the term array we mean either a slice or a fixed-length array with no distinction.

Slices

...