This post will discuss how to delete all items from a list in C#.

1. Using List<T>.Clear() Method

A simple and straightforward solution to remove all elements from a list is using the List<T>.Clear() method. The following example demonstrates usage of the Clear() method to remove all items from a list.

Download  Run Code

2. Using List<T>.Remove() Method

The List<T>.Remove(T) method is used to remove the first occurrence of a specified element from the List<T>. It can be used as follows to remove all items from a list.

Download  Run Code

 
Alternatively, we can use the List<T>.RemoveAt(Int32) method that takes the index of the List<T> and remove the element at that index.

Download  Run Code

3. Using List Constructor

Finally, we can simply assign the list to a new empty list instead of calling Clear() or remove individual items via looping and let the garbage collection kick in. Please note that any other references to the original list object will not be cleared.

Download  Run Code

That’s all about deleting all items from a list in C#.