How to add all the elements of a list to another list in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List<int> list1 = new List<int> { 1, 2, 3 };
        List<int> list2 = new List<int> { 4, 5, 6 };

        list1.AddRange(list2);  // Adds all elements of list2 to list1

        Console.WriteLine(string.Join(", ", list1));  
    }
}


/*
run:

1, 2, 3, 4, 5, 6

*/

 



answered Oct 16, 2025 by avibootz
...