Remove Item at a specified position in a C# List

C# List provides several methods to find and clear items in a list. The Remove method removes the first occurrence of a specific object from a List. The Remove method takes an item as its parameter. The following code snippet removes an item from a List.
// 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 RemoveAt method removes an item at the specified zero-based index. The following code snippet removes an item at the 2nd position in the List.


The RemoveRange method removes an item on the specified starting index and the number of items. The RemoveRange method takes the first parameter as the starting position and the second parameter as the number of items to be removed from the List. The following code snippet removes two items starting at the 3rd position. 

AuthorList.RemoveRange(3, 2);

The Clear method removes all items from the List. For example, the following code snippet removes all items by calling the Clear method.


Next > List Tutorial In C#

Similar Articles
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.