#119 – Arrays

An array in C# is a type that contains a list of items of the same type.  Elements in the list can be referenced by a single variable name and a numerical index.  The first element is accessed using an index value of 0.

For example, below we define a four element array of integer (int) and set its elements to some hard-coded values.

 int[] numbers = new int[4];    //  Declare/create 4-element array of int

 // Set 4 elements to integer values
 numbers[0] = 10;    // 1st element
 numbers[1] = 20;
 numbers[2] = 30;
 numbers[3] = 40;
Advertisements