xxxxxxxxxx
// C# Program to insert the elements of
// a collection into the List<T> at the
// specified index
using System;
using System.Collections;
using System.Collections.Generic;
class Geeks {
// Main Method
public static void Main(String[] args)
{
string[] str1 = { "Geeks",
"for",
"Geeks" };
// Creating an List<T> of strings
// adding str1 elements to List
List<String> firstlist = new List<String>(str1);
// displaying the elements of firstlist
Console.WriteLine("Elements in List: \n");
foreach(string dis in firstlist)
{
Console.WriteLine(dis);
}
Console.WriteLine(" ");
// contains new Elements which is
// to be added in the List
str1 = new string[] { "New",
"Element",
"Added" };
// using InsertRange Method
Console.WriteLine("InsertRange(2, str1)\n");
// adding elements after 2nd
// index of the List
firstlist.InsertRange(2, str1);
// displaying the elements of
// List after InsertRange Method
foreach(string res in firstlist)
{
Console.WriteLine(res);
}
}
}