If you are learning C# then you will encounter C# collection and C# list, which are very important topics in learning C#, so in this article, I am going to provide you console application example to add items in C# list or add multiple items in C# list.

List<T> is a generic collection in C#, which allows you to create strongly typed list of objects, using the list you can create collection of objects, sort the items in list, find the items in list and add/removed items from list at specific index location of item.

List.Add(), List.AddRange(), List.Insert(), and List.InsertRange() methods are used to add and insert items to a List<T>.

Let's create a Console application in your Visual Studio, by navigating to File -> New -> Project -> Select "Windows" from left pane and "Console Application" from right-pane, then name your application and Click "Ok"

We will be creating a C# console program to see example, but here are few code snippets which can be helpful

Initialize and add items in List

  // List initialization and adding elements to the end of the list:    
  List<char> lst = new List<char> { 'a', 'b', 'c' };

Create blank list and add items in List using List.Add()

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

            // Add items using Add method   
            StudentName.Add("Vikas lalwani");
            StudentName.Add("Praveen");
            StudentName.Add("Prakash Raj");
            StudentName.Add("Virendra verma");
            StudentName.Add("Dinesh motwani");

Create list and add multiple items in List using List.AddRange()

In previous code example, we were adding list items, one by one, if we want, we can add multiple items in C# list at once using List.AddRange, here is the example for it

          //create blank list of string type
          List<string> authors = new List<string>();

            //string array
            string[] authorNames = {
                "Vikas lalwani",
                "Praveen",
                "Virendra verma",
                "Manali verma"
            };

            //using .AddRange we are adding all items at once
            authors.AddRange(authorNames);

Here is the complete console application example, which considers both of the above examples and output.

using System;
using System.Collections.Generic;

namespace CSharpList
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a list  
            List<string> StudentName = new List<string>();

            // Add items using Add method   
            StudentName.Add("Vikas lalwani");
            StudentName.Add("Praveen");
            StudentName.Add("Prakash Raj");
            StudentName.Add("Virendra verma");
            StudentName.Add("Dinesh motwani");

            Console.WriteLine("List 1");
            ShowListItems(StudentName); //print list items

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

            //string array
            string[] authorNames = {
                "Vikas lalwani",
                "Praveen",
                "Virendra verma",
                "Manali verma"
            };

            authors.AddRange(authorNames);
            Console.WriteLine("List 2");
            ShowListItems(authors); //print list items

            Console.ReadKey();
        }

        //method to show items of list
        public static void ShowListItems(List<string> list)
        {
            foreach (var el in list)
            {
                Console.WriteLine("{0, 3}", el);
            }
            Console.WriteLine();
        }
    }
}

Here is the output of this

List 1
Vikas lalwani
Praveen
Prakash Raj
Virendra verma
Dinesh motwani

List 2
Vikas lalwani
Praveen
Virendra verma
Manali verma

c-sharp-add-list-items-min.png

Add items in C# List of Class type

Suppose, we have a class "Student.cs", and you want to add multiple items of it's type

public class Student{
   public string Name {get;set;}
   public string Email {get;set;}
}

Then you can add items of Student type in C# list, using below code sample

            List<Student> student = new List<Student>();

            student.Add(new Student { Name = "Vikram", Email = "vikram@gmail.com" });
            student.Add(new Student { Name = "Bhanu", Email = "bhanu@gmail.com" });

Or if you want to add multiple items of Student type in C# list, you can also use AddRange() method, as shown in below code sample

           List<Student> studentList = new List<Student>();

            studentList.AddRange(new List<Student>
            {
                 new Student { Name = "Vikram", Email = "vikram@gmail.com" },
                 new Student {Name = "Bhanu", Email = "bhanu@gmail.com" }               
             });

AddRange() takes multiple items in one go, as shown in above C# Code.

That's it, hope these above examples, clear you about how to add single or multiples items in C# list.

You may also like to read

Foreach Loop in C#

Multiple ways to add newline into a String in C#