Array

An array is a data structure that stores a set of elements of the same type in a specific, continuous order. Each element has its own unique number — an index. In simpler terms, it is a numbered sequence of cells, where each cell holds a value.

What is an index

An index is the position number of an element in an array. It shows exactly where in the array a specific value is located. You can think of an index as the address of a cell that you can use to find or change an element. In C#, indexes start at zero. If you access an index that does not exist — the program will throw an error (IndexOutOfRangeException).

A real-life analogy

In real life, you can find arrays everywhere, for example, a row of seats in a movie theater:
  • The entire row of seats is an array.
  • Each seat is a cell of the array.
  • A viewer is the value of an array cell.
  • The seat number is the index. The only difference is that in arrays the index starts at 0. If you want to know who is sitting in the 3rd seat — you access index [2].

Array operations:

  • creation
  • reading by index
  • writing by index, adding, deleting
  • iteration, searching
  • sorting
These operations will be covered in detail throughout the course.