How to Delete All Items Of A C# List

How to Remove or Clear All Items of a C# List

We can use the Clear method of C# List to clear the list.

C# List class provides methods and properties to create a list of objects (classes). You can add items to a list during the initialization or using List.Add() and List.AddRange() methods. List is a generic class.

You must import the following namespace before using the List class.

using System.Collections.Generic; 

// Create a list of strings
List<string> AuthorList = new List<string>();  
AuthorList.Add("Mahesh Chand");  
AuthorList.Add("Praveen Kumar");  
AuthorList.Add("Raj Kumar");  
AuthorList.Add("Nipun Tomar");  
AuthorList.Add("Dinesh Beniwal");  
AuthorList.Remove("Mahesh Chand");

The Clear method removes all items of a C# List. The following code snippet removes all items by calling the Clear method.

AuthorList.Clear();

Next > List Tutorial In C#

 

 


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.