← Back to C# Course | Chapter 9: Collections | Lesson 2 of 7

List<T>

In this page:

  1. List<T>

List<T>

List<T> is a dynamically resizable collection from System.Collections.Generic, unlike fixed-size arrays. You can add, remove, and search elements, and it grows automatically as needed. It's the most commonly used general-purpose collection in C#.

Note: Prefer List<T> over arrays whenever the number of elements can change at runtime.

Example: List<T>

markup
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<string> names = new List<string> { "Amy", "Bo" };
        names.Add("Cy");
        names.Remove("Bo");

        Console.WriteLine(names.Count);
        foreach (string name in names)
        {
            Console.WriteLine(name);
        }
    }
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.