Reader Level:
ARTICLE

How to Add Items to a C# List

On July 06, 2012 Articles | How do I
How to add items to a List using C#.
  • 0
  • 0
  • 40370

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" };
AuthorList.AddRange(authors);

Download Free book: Programming List with C#

Mahesh Chand

Mahesh Chand is founder of C# Corner. C# Corner founded in 1999 is a FREE member contributions based open platform for developers to solve problems, learn new technology and hang out.  M...

  • 1rank
  • 71M readers
  • 9times
COMMENT USING

Trending up