Thuta Learning
IntermediateProgrammingbeginner

Arrays

Relax. We'll talk through this in plain words — no textbook voice.

Array is a fixed-size collection that stores multiple values of the same type in one place. Array indexes start at 0, so to get the first item you write array[0].

csharp
string[] courses = { "C#", "JavaScript", "PHP", "Java" };

Console.WriteLine(courses[0]);

courses[1] = "TypeScript";
Console.WriteLine(courses[1]);

Console.WriteLine($"Total courses: {courses.Length}");

Key things to know

  • courses[0] grabs the first item.
  • courses[1] = "TypeScript"; changes the second item.
  • Length gives you back how many items are in the array.
You should see
C# TypeScript Total courses: 4

Info

⚠️ Common mistake

Forget that array indexes start at 0, and grabbing the last item as courses[4] will throw an error. In this example, the last item is actually courses[3].

Arrays | Thuta Learning