List or Array InsertRange Method

vishalneeraj-24503
Posted by vishalneeraj-24503 under C# category on | Points: 40 | Views : 903
InsertRange() is a List static method.It places a collection of elements into a certain index of a List.

For Example:-

System.Collections.Generic.List<int> lst_id = new System.Collections.Generic.List<int>();

lst_id.Add(1);
lst_id.Add(2);
lst_id.Add(4);
lst_id.Add(7);

Output: Before Insert list will contain
1
2
4
7

int[] numbers = new int[3];

numbers[0] = 7;
numbers[1] = 6;
numbers[2] = 7;

lst_id.InsertRange(1, numbers);

foreach (int index_value in lst_id)
{
Response.Write("<br/>" + index_value);
}

Output: After Insert list will contain
1
7
6
7
2
4
7

Comments or Responses

Login to post response