C# List

Beginner
7 min read
Updated: Nov 2026
3 examples
List

Definition and Usage

In C#, List<T> is a resizable, ordered collection. Think of a shopping list on paper: the items have a position, you can add a new line at the end (or squeeze one in the middle), and the same item can appear twice. You put items in with Add(), ask about them with Contains(), and take them out with Remove().

A List reads an item by index in O(1) time, so list[2] is fast. Searching by value with Contains or IndexOf scans the list from the start, so it takes longer when the list is big. It lives in the System.Collections.Generic namespace, so add using System.Collections.Generic; at the top of your file.

The List Methods index lists every method guide in this series.

Items keep their order.

A List never reorders itself. Items stay where you put them until you call a method such as Sort, Reverse, Insert, or Remove. That is why printing a List gives the same output on every run.

C# Syntax

Common first steps:

C#
using System.Collections.Generic;

List<string> names = new List<string>();
names.Add("Asha");                       // add at the end
names.Insert(0, "Zed");                  // add at index 0
string first = names[0];                 // read by index: "Zed"
bool has = names.Contains("Asha");       // true
int total = names.Count;                 // 2

// Create a list with starting items:
List<int> nums = new List<int> { 5, 10, 15 };

List vs Array, Dictionary, and HashSet

Pick the collection that matches what you need to do most:

TypeStoresOrder and repeatsGood for
List<T>Items by positionKeeps order, allows repeats, can growAn ordered collection that changes size
T[] (array)Items by positionKeeps order, allows repeats, fixed lengthA fixed number of items; simple APIs
Dictionary<TKey,TValue>Key and value pairsUnique keys, no promised orderFinding a value from a key
HashSet<T>Unique itemsNo repeats, no promised orderFast "is it in there?" checks and removing duplicates

Learn more on the C# Array, C# Dictionary, and C# HashSet pages.

Count vs Capacity

A List keeps its items in a hidden array. Two numbers describe it. Do not mix them up:

PropertyMeaningCan you set it?
CountHow many items are in the list right nowNo. It changes when you add or remove items.
CapacityHow many items fit before the list must growYes, but never below Count. See EnsureCapacity() and TrimExcess().

C# Examples

Example 1 — Add, Index, Contains, and Remove

A first program: add three names, read one by index, check for a name, remove it, and look at Count.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<string> names = new List<string>();
        names.Add("Asha");
        names.Add("Ben");
        names.Add("Chen");

        Console.WriteLine(names[1]);
        Console.WriteLine(names.Contains("Chen"));
        Console.WriteLine(names.Remove("Ben"));
        Console.WriteLine(names.Count);
        Console.WriteLine(names[1]);
    }
}

How It Works

  1. Type with one part. List<string> means every item in the list is a string. The list starts empty, and Add puts each name at the end.
  2. Index starts at 0. names[1] is the second item, "Ben". Reading an index that does not exist throws ArgumentOutOfRangeException.
  3. Yes or no questions. Contains("Chen") is True. Remove("Ben") removes the first match and also returns True because it found one.
  4. Items slide left. After the remove, Count is 2, and "Chen" moved from index 2 down to index 1, so names[1] now prints Chen.

Example 2 — Count Versus Capacity

Count is how many items are in the list. Capacity is how many it can hold before it must grow. The program prints only answers that are always the same.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<int> list = new List<int>();
        Console.WriteLine(list.Count);

        for (int i = 1; i <= 5; i++) {
            list.Add(i * 10);
        }

        Console.WriteLine(list.Count);
        Console.WriteLine(list.Capacity >= list.Count);

        list.Clear();
        Console.WriteLine(list.Count);
        Console.WriteLine(list.Capacity >= 5);
    }
}

How It Works

  1. Count counts items. A new list has Count 0. After five Add calls it is 5, because each call adds exactly one item.
  2. Capacity is hidden room. The list keeps a bigger inside array so that Add does not need to copy everything each time. Capacity is never smaller than Count, so the comparison prints True.
  3. Exact numbers vary. The growth rule is an internal detail, so the program does not print the capacity itself. It prints only a comparison that is true on every .NET version.
  4. Clear keeps the room. Clear sets Count back to 0 but keeps the inside array, so Capacity is still at least 5.

Example 3 — Loop, Sort, and Search

Sort a list of numbers, loop over it with foreach, and use IndexOf and Find to look for items.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<int> scores = new List<int> { 70, 95, 82, 60 };
        scores.Sort();

        foreach (int s in scores) {
            Console.WriteLine(s);
        }

        Console.WriteLine(scores.IndexOf(82));
        Console.WriteLine(scores.Find(s => s > 90));
    }
}

How It Works

  1. Collection initializer. { 70, 95, 82, 60 } fills the list when it is created. The items keep this order until you change it.
  2. Sort changes the list. Sort() puts the same list in ascending order, so foreach prints 60, 70, 82, 95, one per line. A List has a fixed order, so no extra sorting is needed to get steady output.
  3. IndexOf gives a position. After sorting, 82 sits at index 2, so IndexOf(82) prints 2. A missing value would give -1.
  4. Find uses a rule. s => s > 90 is a lambda: a tiny function that answers true or false for one item. Find returns the first item that passes, which is 95.

Next: C# List Methods Index

After you know what a List is for, open the method index for a full tutorial on each List API.

Start withWhy
Add()Put an item at the end of the list
Contains()Check whether a value is in the list
Remove()Delete the first item that matches a value
Sort()Put the items in order

Full list: C# List Methods index (/c-sharp/list/method).

Frequently Asked Questions

List<T> is a resizable, ordered collection in System.Collections.Generic. It keeps items by position, lets you read them by index, allows duplicates, and grows as you add items.
An array has a fixed length that you choose when you create it. A List grows and shrinks with Add, Insert, Remove, and similar methods. Both use zero-based indexes. Arrays use Length; Lists use Count.
Count is the number of items in the list right now. Capacity is the size of the hidden array behind the list, which is always at least Count. When Count would pass Capacity, the list allocates a bigger array and copies the items over.
Yes. You can add the same value many times. Remove deletes only the first match, while RemoveAll deletes every item that passes a test.
Open the C# List Methods index. It lists Add, AddRange, Insert, Remove, RemoveAll, Find, FindAll, Sort, Reverse, BinarySearch, GetRange, Slice, ToArray, ConvertAll, and every other List method, each with examples and FAQs.

Browse every List method

Open the methods index for categorized guides with examples and FAQs.

List Methods Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful