C# ArrayList InsertRange

Description

ArrayList InsertRange inserts the elements of a collection into the ArrayList at the specified index.

Syntax

ArrayList.InsertRange has the following syntax.


public virtual void InsertRange(
  int index,
  ICollection c
)

Parameters

ArrayList.InsertRange has the following parameters.

  • index - The zero-based index at which the new elements should be inserted.
  • c - The ICollection whose elements should be inserted into the ArrayList. The collection itself cannot be null, but it can contain elements that are null.

Returns

ArrayList.InsertRange method returns

Example

The following code example shows how to insert elements into the ArrayList.


/*w  w w . j ava2 s . co m*/
using System;
using System.Collections;
 public class SamplesArrayList  {

    public static void Main()  {
       ArrayList myAL = new ArrayList();
       myAL.Insert( 0, "A" );
       myAL.Insert( 1, "B" );
       myAL.Insert( 2, "C" );
       myAL.Insert( 3, "D" );
       myAL.Insert( 4, "E" );
       myAL.Insert( 5, "F" );

       // Creates and initializes a new Queue.
       Queue myQueue = new Queue();
       myQueue.Enqueue( "X" );
       myQueue.Enqueue( "Y" );

       myAL.InsertRange( 1, myQueue );

       foreach ( Object obj in myAL )
          Console.WriteLine(obj );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack