How to remove all occurrences of an element from ArrayList in C#

1 Answer

0 votes
using System;
using System.Collections;
      
class Program
{
    public static void PrintArrayList(ArrayList list) { 
         foreach (var e in list) {
            Console.WriteLine(e);
        }
    } 
    static void Main() {
        ArrayList al = new ArrayList();
             
        al.Add("java");
        al.Add("c#");
        al.Add("python");
        al.Add("c");
		al.Add("c#");
        al.Add("php");
		al.Add("c#");
 
        PrintArrayList(al);
         
        while (al.Contains("c#")) {
    		al.Remove("c#");
		}
         
        Console.WriteLine("\n\n");
         
        PrintArrayList(al);
    }
}
     
      
      
/*
run:
      
java
c#
python
c
c#
php
c#



java
python
c
php
      
*/

 



answered May 9, 2020 by avibootz

Related questions

1 answer 166 views
1 answer 147 views
147 views asked Apr 21, 2020 by avibootz
2 answers 217 views
1 answer 84 views
...