C# ArrayList RemoveRange

Description

ArrayList RemoveRange removes a range of elements from the ArrayList.

Syntax

ArrayList.RemoveRange has the following syntax.


public virtual void RemoveRange(
  int index,
  int count
)

Parameters

ArrayList.RemoveRange has the following parameters.

  • index - The zero-based starting index of the range of elements to remove.
  • count - The number of elements to remove.

Returns

ArrayList.RemoveRange method returns

Example

The following code removes range from ArrayList.


using System;/* w w  w .  j  a  v a 2s.  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("csharp");

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

        baseballTeams.AddRange(myStringArray);

        baseballTeams.RemoveRange(2, 2);

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

        Console.ReadLine();

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack