Updated: Jan 18
Arrays are used to store multiple values (from the same type) in a single location instead of declaring separate variables for each value we want to use. By default, the first cell in an array will start with id ‘0’, and the last index will be the number of all items in the array-1.
To declare an array, we need to provide the variable type with square brackets:
Here are a few examples of different arrays with fixed sizes:
Example 1: Create an array with a default number of elements (specified here inside the brackets [ ])
Example 2: Create an array with a default number of elements and add values as part of the array creation.
Example 3: Create an array without a fixed size and add values as part of the array creation.
Working with the Array element
To change the value of a specific element in the array, we can simply use its index number:
Arrays - Methods and Properties
We can access an element of an array by reefing to a specific cell (represented via an index number). Also, I will cover some of the main built-in methods/properties we have in C# that can be very handy when working with arrays.
Extracting arrays information
Here is another example of how to use the ‘clear’ method: