Home About Lessons Blog On The Mic Contact Projects
Lessons BASIC · C#

C# Basics — Array

8 min read · Emre Ulutabak
1
What is an array?

Think of a shoe rack at home. Each shelf holds a shoe, and all of them are stored in one organized structure.

In software, we also want to keep multiple values inside one structure. That is called an array.

csharp
string[] isimler = { "Emre", "Ayşe", "Mehmet" };
💡
An array stores multiple values of the same type under one name.
2
Why is it used?

Defining a separate variable for every student name would be messy and tiring. Keeping them in one structure makes much more sense.

An array makes it easier to store data in bulk and perform operations on it.

3
Index logic

Every item in an array has an order number. This is called an index.

The important detail is this: indexing starts from 0, not from 1.

csharp
string[] isimler = { "Emre", "Ayşe", "Mehmet" };

Console.WriteLine(isimler[0]);
Console.WriteLine(isimler[1]);
💡
The first element is always at index 0.
4
Iterating through an array

To go through all items in an array one by one, you use a loop. That way, you do not have to write each element manually.

csharp
string[] isimler = { "Emre", "Ayşe", "Mehmet" };

for (int i = 0; i < isimler.Length; i++)
{
    Console.WriteLine(isimler[i]);
}
💡
Length gives the total number of items inside the array.
5
Golden rules

Arrays are simple and powerful, but they work with a fixed size. That is why it is important to know when to use an array and when to use another structure.

💡
An array does not grow easily later; you need to plan its size beforehand.
💡
Be careful with index errors. If you try to access a non-existing index, you get an error.
💡
All elements must be of the same type.
MINI QUIZ
Which of the following is correct?
Different types must be stored together in an array
Array indexing usually starts from 0
Length always returns the first element
Arrays only exist for numbers