Back to course

Introduction to Arrays

.NET Zero to Hero: Master C# and Modern App Development

Arrays: Storing Lists of Data

An array stores multiple values of the same type in a single variable.

Declaration:

csharp string[] cars = {"Volvo", "BMW", "Ford"}; int[] numbers = new int[5]; // Stores 5 integers

Accessing Elements:

Arrays are zero-indexed (start at 0). csharp Console.WriteLine(cars[0]); // Outputs Volvo cars[1] = "Tesla"; // Updates BMW to Tesla

Property:

cars.Length gives the size of the array.