Array Slicing

Array slicing involves taking a subset from an array and allocating a new array with those elements.

Some languages, like Javascript or Python, make this really easy:

myArray.slice(startIndex, endIndex);
my_list[start_index:end_index]

In C#, we'd need to allocate a new array and copy over the elements, like this:

var slice = new int[endIndex - startIndex]; Array.Copy(sourceArray, startIndex, slice, 0, slice.Length);

Slicing takes time and space, where n is the number of elements in the resulting array.

. . .