C# List Insert() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
List

Definition

In C#, List.Insert(index, item) adds an item at a position you choose. The item that was at that position, and every item after it, moves one place to the right to make room.

Think of squeezing a new name into the middle of a queue. The valid index is from 0 up to Count. Index 0 puts the item first. Index Count puts it last, which behaves just like Add(). Anything bigger than Count is an error.

This is an instance member of List<T> (System.Collections.Generic). Call it on a list variable, such as numbers.Insert(...). A List<T> is a class, so two variables can share one list. It keeps items in the order you put them, allows duplicates, and grows when needed. An array, by comparison, has a fixed length.

Syntax

Pass the position first and the item second. The position is where the new item will end up.

C#
List<string> names = new List<string> { "Asha", "Chen" };
names.Insert(1, "Ben");     // Asha, Ben, Chen
names.Insert(0, "Zed");     // Zed, Asha, Ben, Chen
CallWhat it does
names.Insert(0, "Zed")Puts "Zed" first. Every old item moves to a higher index.
names.Insert(names.Count, "End")Index equal to Count is allowed and adds at the end.
names.Insert(names.Count + 1, "x")Throws ArgumentOutOfRangeException. The index is past the end.

Insert is O(n), because the items after the position have to be copied one slot to the right. Putting items at the front of a big list again and again is slow. Appending with Add is O(1) most of the time. A negative index also throws ArgumentOutOfRangeException.

Library declarations
C#
public void Insert(int index, T item);

Parameters

ParameterDescription
indexRequired. The zero-based position for the new item. It must be from 0 to Count, including both ends.
itemRequired. The item to insert. A null is allowed when T is a reference type.

Return Value

Return ValueDescription
voidNothing is returned. The list changes in place, and Count increases by 1.

C# Examples

Example 1 — Insert at the Start and in the Middle

Start with two names and add one in the middle and one at the front.

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

class Program {
    static void Main() {
        List<string> names = new List<string> { "Asha", "Chen" };

        names.Insert(1, "Ben");
        Console.WriteLine(string.Join(", ", names));

        names.Insert(0, "Zed");
        Console.WriteLine(string.Join(", ", names));
        Console.WriteLine(names.IndexOf("Chen"));
    }
}

How It Works

  1. Make room at index 1. Insert(1, "Ben") moves "Chen" from index 1 to index 2 and places "Ben" in the gap.
  2. Index 0 means first. Insert(0, "Zed") pushes every existing name one step to the right.
  3. Positions shifted. "Chen" was at index 1, then 2, and is now at 3. Every insert before an item raises its index by one.
  4. Nothing is overwritten. Unlike names[1] = "x", which replaces an item, Insert only adds. Count grows with each call.

Example 2 — Insert at Count and Beyond

Inserting at Count appends. An index above Count throws an exception.

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

class Program {
    static void Main() {
        List<int> list = new List<int> { 10, 20 };

        list.Insert(list.Count, 30);
        Console.WriteLine(string.Join(", ", list));

        try {
            list.Insert(5, 99);
        } catch (ArgumentOutOfRangeException) {
            Console.WriteLine("index 5 is too big");
        }

        Console.WriteLine(list.Count);
    }
}

How It Works

  1. Count is allowed. The list has 2 items, so Insert(2, 30) is legal. It acts like Add and puts 30 last.
  2. Past the end fails. After that, Count is 3, and index 5 would leave gaps at 3 and 4. A list cannot have gaps, so it throws ArgumentOutOfRangeException.
  3. Catch and report. The catch block prints a message so the program keeps running instead of crashing.
  4. No partial change. The failed call did not add 99. Count is still 3 after the exception.

Example 3 — Insert into a Sorted List

Use BinarySearch to find the right position, then Insert the new number there so the list stays in order.

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

class Program {
    static void Main() {
        List<int> sorted = new List<int> { 10, 20, 40, 50 };

        int pos = sorted.BinarySearch(30);
        if (pos < 0) {
            pos = ~pos;
        }

        sorted.Insert(pos, 30);

        Console.WriteLine(pos);
        Console.WriteLine(string.Join(", ", sorted));
    }
}

How It Works

  1. Already in order. The list starts sorted, which BinarySearch needs. Searching an unsorted list gives unreliable answers.
  2. Negative means not found. 30 is missing, so BinarySearch returns a negative number. The bitwise complement ~pos turns it into the index where 30 belongs, which is 2.
  3. Insert at that spot. Insert(2, 30) places 30 between 20 and 40, and the later items shift right.
  4. Still sorted. Because the position came from the search, the list stays in ascending order without calling Sort again.

Frequently Asked Questions

It puts an item at the index you give and moves that item and every later item one place to the right. Count grows by 1.
Yes. Insert(list.Count, item) adds the item at the end, like Add. Only an index above Count (or below 0) throws ArgumentOutOfRangeException.
No. It never overwrites. To replace an item, assign with the indexer, such as list[1] = value.
Yes, when you insert near the front. Insert has to move every item after the position, so it is O(n). Add at the end is O(1) most of the time.
Use InsertRange(index, collection). It moves the later items only once instead of once per item.

Next: InsertRange()

Insert every item of another collection at a chosen index, in order.

InsertRange() tutorial →

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