C# ArrayList Remove

Description

ArrayList Remove removes the first occurrence of a specific object from the ArrayList.

Syntax

ArrayList.Remove has the following syntax.


public virtual void Remove(
  Object obj
)

Parameters

ArrayList.Remove has the following parameters.

  • obj - The Object to remove from the ArrayList. The value can be null.

Returns

ArrayList.Remove method returns

Example


using System; //from ww w  .  j a va2s. c o m
using System.Collections; 
 
class MainClass { 
  public static void Main() { 
    ArrayList al = new ArrayList(); 
     
    Console.WriteLine("Adding 6 elements"); 
    // Add elements to the array list 
    al.Add('C'); 
    al.Add('A'); 
    al.Add('E'); 
    al.Add('B'); 
    al.Add('D'); 
    al.Add('F'); 
 
    Console.WriteLine("Removing 2 elements"); 
    // Remove elements from the array list. 
    al.Remove('F'); 
    al.Remove('A'); 
 
    Console.WriteLine("Number of elements: " + 
                       al.Count); 
  }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack