Home »
.Net »
C# Programs
C# - ArrayList.Remove() Method with Example
C# ArrayList.Remove() Method: Here, we are going to learn how to remove the first occurrence of a specific object from the ArrayList in C#.Net?
By Nidhi Last updated : April 03, 2023
ArrayList.Remove() Method
The ArrayList.Remove() method is used to remove the first occurrence of the given object from the ArrayList.
Syntax
void ArrayList.Remove(object item);
Parameter(s)
- item: An object to be deleted from the ArrayList.
Return Value
It does not return any value.
Exception(s)
- System.NotSupportedException
C# program to remove the first occurrence of a specific object from the ArrayList
The source code to remove the first occurrence of a specific object from the ArrayList is given below. The given program is compiled and executed successfully.
using System;
using System.Collections;
namespace mynamespace {
class Program {
//Entry point of program
static void Main(string[] args) {
ArrayList List = new ArrayList();
List.Add("ABC");
List.Add("XYZ");
List.Add("PQR");
List.Add(1.15);
List.Add(2.25);
List.Add(3.35);
List.Add(4.45);
List.Add(5.55);
object[] objArray1 = List.ToArray();
Console.WriteLine("Values in array list before Remove");
foreach(object val in objArray1) {
Console.WriteLine(val);
}
List.Remove("XYZ");
object[] objArray2 = List.ToArray();
Console.WriteLine("\n\nValues in array list after remove");
foreach(object val in objArray2) {
Console.WriteLine(val);
}
}
}
}
Output
Values in array list before Remove
ABC
XYZ
PQR
1.15
2.25
3.35
4.45
5.55
Values in array list after remove
ABC
PQR
1.15
2.25
3.35
4.45
5.55
Press any key to continue . . .
C# ArrayList Class Programs »