Insert the elements of a collection into the ArrayList at the specified index in CSharp
Description
The following code shows how to insert the elements of a collection into the ArrayList at the specified index.
Example
using System;//from ww w . j a v a2 s.c om
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" );
foreach ( Object obj in myAL )
Console.WriteLine(obj );
// 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.