List<T> is a collection whose size can change. Arrays are fixed-size, but with a List you can add, remove, and search for items much more easily. When you don't know ahead of time how many items you'll have, List is the go-to choice in real projects.
csharp
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
List<string> tasks = new List<string>();
tasks.Add("Learn C# basics");
tasks.Add("Practice methods");
tasks.Add("Build a mini project");
tasks.Remove("Practice methods");
foreach (string task in tasks)
{
Console.WriteLine(task);
}
}
}What you'll learn from this code
using System.Collections.Generic;needs to be added before you can useList<T>.Add()adds an item.Remove()removes an item.foreachloops through every item in the list.
You should see
Learn C# basics Build a mini project