How to add a range of elements from one list to another in C#

1 Answer

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

public class Program
{
    public static void Main()
    {
        var list1 = new List<string>() { "vb.net", "c#", "java", "c", "c++", "python", "rust" };
        List<string> list2 = new List<string>();

        list2.AddRange(list1.GetRange(2, 3));

        foreach (string s in list2)
            Console.WriteLine(s + " ");
    }
}




/*
run:

java 
c 
c++

*/

 



answered Mar 8, 2023 by avibootz

Related questions

...