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

C# Basics — List

8 min read · Emre Ulutabak
1
What is a list?

Think of a shopping list. Today you write down three products, then later two more come to mind and you add them.

In software, one of the structures whose size can change later is a List. Adding and removing items is more flexible.

csharp
List<string> isimler = new List<string>();
💡
A List is very useful for storing data with dynamic size.
2
Difference from array

An array has fixed size, while a List can grow and shrink. That is why a List is more convenient when the number of items is not known in advance

3
Adding items

To add new data into a List, you usually use Add. The structure expands automatically when needed.

csharp
List<string> sehirler = new List<string>();
sehirler.Add("İstanbul");
sehirler.Add("Ankara");
sehirler.Add("İzmir");
💡
The Add method appends a new item to the end of the list.
4
Removing items and access

You can access items in a List by index, just like in an array. You can also use methods like Remove to delete items.

csharp
List<string> sehirler = new List<string> { "İstanbul", "Ankara", "İzmir" };

Console.WriteLine(sehirler[0]);
sehirler.Remove("Ankara");
💡
A List also works with indexing; the first element is again at index 0.
5
Golden rules

A List is very practical, but like every data structure, you should know where and why you use it.

💡
If the size will change, a List is often more suitable than an array.
💡
Choose the type correctly. List<int> and List<string> hold different kinds of data.
💡
Think of a List as a collection, not as individual separate variables.
MINI QUIZ
Which of the following is correct?
A List has fixed size and cannot grow
A List can store dynamically sized data
There is no index in a List
The Add method removes items