Reader Level:

How to Add Items to a C# List

By Mahesh Chand on Jul 06, 2012
How to add items to a List using C#.

Add Items 

The Add method adds an item to a List. The following code snippet creates a List and adds items to it by using the Add method. 

// Create a list
List<string> AuthorList = new List<string>();

// Add items using Add method 
AuthorList.Add("Mahesh Chand");
AuthorList.Add("Praveen Kumar");
AuthorList.Add("Raj Kumar");
AuthorList.Add("Nipun Tomar");
AuthorList.Add("Dinesh Beniwal");

The AddRange method is used to add a collection of items. The following code snippet adds a collection of items to a List. 

// Add a range of items
string[] authors = { "Mike Gold", "Don Box",
                        "Sundar Lal", "Neel Beniwal" };

Download Free book: Programming List with C#

Mahesh Chand
Mahesh Chand

C# Corner founder, 10-times Microsoft MVP, technical author, and software architect. Mahesh authored his first book, A Programmer’s Guide to ADO.NET in C# with APress at the age of 25. C# Corner is a memb... Read more



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.

Trending up

Infragistics jQuery Controls