How to remove all the occurrences of a string from StringCollection in C#

1 Answer

0 votes
using System;
using System.Collections.Specialized; 
                     
public class Program
{
    public static void Main()
    {
        StringCollection sc = new StringCollection(); 
   
        sc.Add("c#"); 
        sc.Add("c++"); 
        sc.Add("java"); 
        sc.Add("c#"); 
        sc.Add("php"); 
        sc.Add("python"); 
        sc.Add("c#"); 

        while (sc.Contains("c#"))
			sc.Remove("c#");
		       
		foreach (string s in sc) {
            Console.WriteLine(s);
        }
    }
}
 
 
 
/*
run:
 
c++
java
php
python
 
*/

 



answered May 9, 2020 by avibootz

Related questions

1 answer 141 views
1 answer 163 views
1 answer 128 views
1 answer 85 views
1 answer 167 views
1 answer 185 views
...