Back to course

Introduction to Arrays

C# Zero to Hero: Comprehensive Programming Masterclass

Arrays

Arrays are used to store multiple values of the same type in a single variable.

Declaration

csharp string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; int[] myNumbers = {10, 20, 30, 40};

Accessing Elements

Arrays are zero-indexed. csharp Console.WriteLine(cars[0]); // Outputs: Volvo

Changing Elements

csharp cars[0] = "Opel";

Array Length

csharp Console.WriteLine(cars.Length);