C# List Methods

About This Index
This page is the C# List Methods index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs. Examples use small fixed data such as List<int> and List<string>. A List keeps its items in order, so the printed output is the same every time you run the program.
Learn what a List is for on /c-sharp/list. Use this page when you need a specific API such as Add(), Remove(), or FindAll().
A List stores items by position (list[0], list[1], ...), allows repeats, and grows as you add. Count is how many items it holds. Capacity is how many it can hold before it must grow.
How to Call a List Method
Every List method is an instance method, so you call it on your list variable:
List<int> numbers = new List<int>();
numbers.Add(30); // add one item at the end
numbers.AddRange(new int[] { 10, 20 }); // add many items at once
numbers.Sort(); // 10, 20, 30
int pos = numbers.IndexOf(20); // 1 (or -1 when missing)
int big = numbers.Find(x => x > 15); // 20, the first item that passes the test
bool gone = numbers.Remove(10); // remove the first 10 C# List Methods Table
All method guides in this C# tutorial series (32 tutorials), grouped by purpose.
Add / insert
4 methodsPut one item or many items into the list, at the end or at a chosen position.
| Method | Description | Tutorial |
|---|---|---|
Add() | Add one item to the end of a List; Count goes up by 1. | Try it |
AddRange() | Add every item of another collection to the end of a List in one call. | Try it |
Insert() | Put one item at a chosen index and move the later items one place to the right. | Try it |
InsertRange() | Insert every item of another collection at a chosen index, in order. | Try it |
Remove
5 methodsTake items out by value, by position, by a rule, by a range, or empty the whole list.
| Method | Description | Tutorial |
|---|---|---|
Remove() | Remove the first item that equals a value; returns true if one was removed. | Try it |
RemoveAt() | Remove the item at a given index and move later items one place to the left. | Try it |
RemoveAll() | Remove every item that passes a test (a predicate); returns how many were removed. | Try it |
RemoveRange() | Remove a block of count items that starts at a given index. | Try it |
Clear() | Remove every item from the List; Count becomes 0 and Capacity stays the same. | Try it |
Search
11 methodsCheck whether something is in the list, find its position, or find items with a rule (a small test function).
| Method | Description | Tutorial |
|---|---|---|
Contains() | Check whether the List holds an item that equals a value; returns true or false. | Try it |
IndexOf() | Return the index of the first item that equals a value, or -1 if it is not found. | Try it |
LastIndexOf() | Return the index of the last item that equals a value, searching from the end. | Try it |
BinarySearch() | Fast search in a sorted List; returns the index, or a negative number when missing. | Try it |
Exists() | Return true if at least one item passes a test (a predicate). | Try it |
Find() | Return the first item that passes a test, or the default value (0 or null) if none does. | Try it |
FindAll() | Return a new List with every item that passes a test. | Try it |
FindIndex() | Return the index of the first item that passes a test, or -1 if none does. | Try it |
FindLast() | Return the last item that passes a test, or the default value (0 or null) if none does. | Try it |
FindLastIndex() | Return the index of the last item that passes a test, searching backward; -1 if none does. | Try it |
TrueForAll() | Return true if every item passes a test; an empty list gives true. | Try it |
Reorder
2 methodsSort the list or flip it around. Both change the list you call them on.
Copy / convert
6 methodsMake a new list, an array, a converted list, or a read-only view of the list.
| Method | Description | Tutorial |
|---|---|---|
GetRange() | Copy a block of count items, starting at an index, into a new List. | Try it |
Slice() | Copy a block of items into a new List; also what the list[1..4] range syntax calls. | Try it |
ToArray() | Copy the items of the List into a new array of the same length. | Try it |
CopyTo() | Copy items from the List into an existing array, starting at a chosen position. | Try it |
ConvertAll() | Create a new List by converting every item with a function (a Converter). | Try it |
AsReadOnly() | Return a read-only wrapper around the List; it reflects later changes to the source list. | Try it |
Loop
2 methodsRun code for every item, or get the enumerator that foreach uses behind the scenes.
| Method | Description | Tutorial |
|---|---|---|
ForEach() | Run an action (a lambda) once for every item in the List, in order. | Try it |
GetEnumerator() | Return the enumerator that foreach uses to walk through the List one item at a time. | Try it |
Capacity
2 methodsReserve space before a big load, or give back unused space after a clean-up.
| Method | Description | Tutorial |
|---|---|---|
EnsureCapacity() | Make room for at least a number of items before adding them, so the List grows less often. | Try it |
TrimExcess() | Give back unused room so Capacity moves close to Count (does nothing if the List is nearly full). | Try it |
Frequently Asked Questions
Start with Add()
Put your first item into a list and see how Count and the index work.
12 people found this page helpful
