How to clear all items of a C# list?

How to clear a C# list?

 

How to clear all items of a C# list

 

Delete All Items (Clear a C# list)

 

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

You need to import the following namespace before using the List class.

 

By using System.Collections.Generic; 

// Create a list of strings  

List<string> AuthorList = new List<string>();  

AuthorList.Add(“CLEARALIST1”);  

AuthorList.Add(“CLEARALIST2”);  

AuthorList.Add(“CLEARALIST3”);  

AuthorList.Add(“CLEARALIST4”);  

AuthorList.Add(“CLEARALIST5”);  

AuthorList.Remove(“CLEARALIST1”);

The Clear method excludes all items from the list. The later code snippet deletes all items by calling the Clear method. 

 

Output –

AuthorList.Clear();

 

You May Also Read This – 

Various ways to clear a list in Python & C++

Clean your bad, spam email list and increase your mail sending reputation using Clearalist – Email list cleaning service

Clearalist email list cleaning service provider satisfies all types of business firms and marketers. They have implemented an easy to use list validating functionality in which you simply upload a bulk email list, click on the clean list button and get your list scrubbed. Over a thousand of users trust Clearalist for their real-time email verification and list cleaning services. Clearalist ensures you reach your customers by dramatically increasing the delivery of your emails to the inbox. By removing outdated email addresses and checking if an email is valid, the Clearalist Email Scrubbing Service provider improves deliverability and helps businesses grow in no time.
Email List Cleaning is removing unengaged subscribers from your email list so that you can sell only to people who desire to receive your emails. Email list hygiene is a vital part of targeting your marketing, hence you must do email list cleanup at least a couple of times a year.

Leave a Reply