Declare a new ArrayList and add elements to it.
ArrayList arr = new ArrayList(); arr.Add( "One" ); arr.Add( "Two" ); arr.Add( "Three" ); arr.Add( "Four" );
Now let’s say you need to remove the element “Three”. For that, use the Remove() method.
arr.Remove("Three");The following is the complete example to remove an element from ArrayList −
Example
using System;
using System.Collections;
class Demo {
static void Main() {
ArrayList arr = new ArrayList();
arr.Add( "One" );
arr.Add( "Two" );
arr.Add( "Three" );
arr.Add( "Four" );
Console.WriteLine("ArrayList...");
foreach(string str in arr) {
Console.WriteLine(str);
}
arr.Remove("Three");
Console.WriteLine("ArrayList after removing an element...");
foreach(string str in arr) {
Console.WriteLine(str);
}
Console.ReadLine();
}
}Output
ArrayList... One Two Three Four ArrayList after removing an element... One Two Four