Skip to content
dreamcode
dreamcode
Map
Arrays
Lesson 6 of 21
+15 XP on finish
C# LOOPS & ARRAYSChapter 2 · C# Loops & Arrays

Fixed-size arrays

An array stores multiple elements of the same type in a single variable. Its size is fixed when created. Access elements using zero-based indices.

Worked example
string[] clouds = new string[] { "wispy", "puffy", "grey" };
Console.WriteLine(clouds.Length); // 3
Console.WriteLine(clouds[0]); // wispy

foreach (string cloud in clouds) {
    Console.WriteLine(cloud);
}

How it reads

  • string[] declares a variable that holds an array of strings
  • new string[] { ... } creates the array with starting values
  • clouds.Length returns the number of items in the array
Cloud tip: Since arrays have a fixed size, you cannot add or remove elements after creation. If you need a dynamic size, use List<T>.

Check your understanding

0 / 2

Answer all 2 to complete this lesson and earn 15 XP.

  1. 1. What property retrieves the total number of elements in a C# array?
  2. 2. Which keyword iterates over elements without keeping an explicit index variable?
Answer every question to unlock the next lesson.