Remove the first occurrence of a specific object from the ArrayList in CSharp
Description
The following code shows how to remove the first occurrence of a specific object from the ArrayList.
Example
using System; //from ww w . ja v a 2 s .c o m
using System.Collections;
class MainClass {
public static void Main() {
ArrayList al = new ArrayList();
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);
foreach(string s in al){
Console.WriteLine(s);
}
}
}
The code above generates the following result.