C# List Insert: Syntax, Behavior, and Performance
Learn how to use List<T>.Insert in C# to add elements at a specific index, understand its O(n) shifting behavior, and know when to choose alternatives.

The List<T>.Insert method in C# adds an element at a specified zero-based index and shifts any following elements to the right. Unlike Add, which appends to the end, Insert lets you place an item at an exact position in an existing list.
Inserting an Element at a Specific Index
The List<T>.Insert method is defined on the List<T> class and takes two parameters: the zero-based index at which to insert the item, and the item itself. The method returns void; it modifies the list in place. Here is a minimal example:
List<string> names = new List<string> { "Alice", "Charlie" };
names.Insert(1, "Bob");
// names is now: "Alice", "Bob", "Charlie"In this example, "Bob" is inserted at index 1, pushing "Charlie" to index 2. The original elements after the insertion point are shifted right by one position.
Syntax and Basic Usage
The method signature is public void Insert(int index, T item). The index parameter must be between 0 and Count, inclusive. If index equals Count, the item is appended to the end, making Insert equivalent to Add in that case. If index is out of range, an ArgumentOutOfRangeException is thrown.
List<int> numbers = new List<int> { 1, 2, 3 };
numbers.Insert(0, 0); // Insert at the beginning
numbers.Insert(numbers.Count, 4); // Insert at the end, same as AddWhen inserting at the beginning, all existing elements shift right. This is a common pattern for building a reverse-ordered list, though it is not efficient for large lists because each insertion is O(n).
What Happens When You Insert
Internally, List<T> stores elements in an array. When you call Insert, the runtime must make room for the new element by shifting the elements from the insertion index to the end one position to the right. This shift is an O(k) operation, where k is the number of elements after the insertion point; in the worst case, inserting near the beginning shifts the entire list, making it O(n) in the list length.
If the internal array is already full, the list first allocates a new, larger array and copies the existing elements into it. That copy adds overhead on top of the shift, so capacity management is another reason to prefer Add when the position does not matter. If you know the final size ahead of time, you can use the List<T>(int capacity) constructor to reduce resizing.
Insert vs Add: Choosing the Right Method
Add appends an element to the end of the list and runs in amortized O(1) time. Insert runs in O(n) time because of the shifting. The choice between them depends on whether the position matters. If you always add elements in order, Add is the natural and efficient choice. Use Insert only when the element must appear at a specific index.
| Operation | Time Complexity | Use Case |
|---|---|---|
Add | Amortized O(1) | Append to the end |
Insert | O(n) | Place at a specific index |
For example, maintaining a sorted list by inserting each new element at the correct position is a common pattern, but it becomes expensive for large lists. In such cases, consider whether another collection better fits the access pattern: LinkedList<T> helps when you have a node reference, and SortedSet<T> can help when you need unique sorted elements.
Performance and Memory Implications
The O(n) shifting behavior of Insert is the primary performance concern. Each insertion moves a contiguous block of memory, which is fast for small lists but becomes noticeable as the list grows. If you perform many insertions at arbitrary positions, especially at the beginning, the total cost can be quadratic.
Memory usage also matters. When the internal array needs to grow, List<T> allocates a new, larger array and copies the existing elements, so the old and new arrays exist at the same time during the resize. If you know the final size ahead of time, use the List<T>(int capacity) constructor to preallocate and reduce resize overhead.
Handling Index Errors and Edge Cases
The Insert method throws an ArgumentOutOfRangeException if index is less than 0 or greater than Count. This is a common source of runtime errors, especially when the index is derived from user input or external data. Always validate the index before calling Insert, or wrap the call in a try-catch if the index is not guaranteed to be valid.
Another edge case is inserting into an empty list. If Count is 0, the only valid index is 0. Inserting at index 0 on an empty list works and is equivalent to Add. Inserting at any other index throws an exception.
InsertRange and Related Methods
List<T> also provides InsertRange(int index, IEnumerable<T> collection), which inserts multiple elements at a given index. This is more efficient than calling Insert in a loop because it shifts the existing elements only once, rather than once per inserted item. The collection is inserted in order, so the first element of the collection lands at the specified index.
List<int> list = new List<int> { 1, 4 };
list.InsertRange(1, new[] { 2, 3 });
// list is now: 1, 2, 3, 4If you need to insert a large batch of items, prefer InsertRange over repeated Insert calls. The same O(n) shifting applies, but the constant factor is lower because the shift happens once.
When a LinkedList Is a Better Choice
If your application frequently inserts elements in the middle of a large collection, List<T>.Insert may not be the best data structure. A LinkedList<T> offers O(1) insertion at a known node, but it does not support index-based access. You must traverse the list to find the insertion point, which is O(n). The tradeoff depends on your access patterns.
Use List<T> when you need fast random access by index and insertions are rare or happen near the end. Use LinkedList<T> when you have a reference to a node and need to insert around it frequently. For most scenarios, List<T> is the pragmatic choice because of its cache-friendly array storage and lower memory overhead per element. For large lists with many insertions in the middle, benchmark the behavior and consider a structure designed for ordered inserts, such as SortedSet<T> if duplicate elements are not needed.
Try matching browser tools
All toolsSmall utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related C# guides
All C# guidesC# Dispose vs Destructor: Key Differences Explained
c# dispose vs destructor: Understand the difference between Dispose and destructors in C#, when each runs, and how to manage unmanaged resources correctly.
C# Variable Declaration: Syntax and Practical Usage
Learn how to declare variables in C# with explicit types, var, and nullable annotations, and understand how defaults, scope, and readability affect your choices.
C# Primary Constructors for Classes: Syntax and Usage
Learn how to use C# primary constructors for classes: syntax, initialization, dependency injection, and limitations with practical examples.
C# IComparer: Custom Sorting with IComparer<T>
Learn how to implement IComparer<T> in C# to define custom sort order for arrays and lists, handle nulls, and avoid common performance pitfalls.
More in C#
All C# guidesThe guides filed next to this one in C#, in library order.