How to Add Items to a C# List

The List<T> class in C# and .NET represents a strongly typed list of objects. List<T> provides functionality to create a collection of objects, find list items, sort list, search list, and manipulate list items. In List<T>, T is the type of objects. The code examples in this article demonstrates how to add items to a List using C#.
C# List<T> class represents a collection of a type in C#. List.Add(), List.AddRange(), List.Insert(), and List.InsertRange() methods are used to add and insert items to a List<T>.
List<T> is a generic class. You must import the following namespace before using the List<T> class.
using System.Collections.Generic;

List.Add() Method

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. 
  1. // Create a list  
  2. List<string> AuthorList = new List<string>();  
  4. // Add items using Add method   
  5. AuthorList.Add("Mahesh Chand");  
  6. AuthorList.Add("Praveen Kumar");  
  7. AuthorList.Add("Raj Kumar");  
  8. AuthorList.Add("Nipun Tomar");  
  9. AuthorList.Add("Dinesh Beniwal");  

List.AddRange() Method

The AddRange method is used to add a collection of items. The following code snippet adds a collection of items to a List. 
  1. // Add a range of items  
  2. string[] authors = { "Mike Gold""Don Box",  
  3.                         "Sundar Lal""Neel Beniwal" };  
  4. AuthorList.AddRange(authors);  
Download Free book: Programming List with C#