C# ArrayList AddRange

Description

ArrayList AddRange adds the elements of an ICollection to the end of the ArrayList.

Syntax

ArrayList.AddRange has the following syntax.


public virtual void AddRange(
  ICollection c
)

Parameters

ArrayList.AddRange has the following parameters.

  • c - The ICollection whose elements should be added to the end of the ArrayList. The collection itself cannot be null, but it can contain elements that are null.

Returns

ArrayList.AddRange method returns

Example

The following code example shows how to add elements to the ArrayList.


using System;/*from   w  w  w  . jav a2s. c  o  m*/
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program {
    static void Main(string[] args) {
        ArrayList baseballTeams = new ArrayList();
        baseballTeams.Add("java2s.com");
        baseballTeams.Add("r");
        baseballTeams.Add("F");

        string[] myStringArray = new string[2];
        myStringArray[0] = "G";
        myStringArray[1] = "L";

        baseballTeams.AddRange(myStringArray);

        foreach (string item in baseballTeams) {
            Console.Write(item + "\n");
        }

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack