Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove an item from an ArrayList in C#?
Firstly, set a a new ArrayList and add elements to it.
ArrayList arr = new ArrayList(); arr.Add( "Jones" ); arr.Add( "Tom" ); arr.Add( "Henry" );
Now let’s remove the item “Tom”. For that, use the Remove() method.
arr.Remove("Tom");
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( "Jones" );
arr.Add( "Tom" );
arr.Add( "Henry" );
Console.WriteLine("Initial 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
Initial ArrayList... Jones Tom Henry ArrayList after removing an element... Jones Tom Henry
Advertisements