- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 element from Array List in C#?
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
Advertisements