C# | Remove the first occurrence from the StringCollection Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.Remove(String) method is used to remove the first occurrence of a specific string from the StringCollection. Syntax: public void Remove (string value); Here, value is the string which is to be removed from the StringCollection. The value can be null. Note: Duplicate strings are allowed in StringCollection. Only the first occurrence is removed. To remove all occurrences of the specified string, use RemoveAt(IndexOf(value)) repeatedly while IndexOf does not return -1. If the StringCollection does not contain the specified object, the StringCollection remains unchanged. No exception is thrown. This method performs a linear search; therefore, this method is an O(n) operation, where n is Count. Example: CSHARP // C# code to remove the first // occurrence of a specific string // from the StringCollection using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // creating a StringCollection named myCol StringCollection myCol = new StringCollection(); // creating a string array named myArr String[] myArr = new String[] {"A", "A", "A", "B", "C", "C", "D", "D", "E"}; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); Console.WriteLine("Elements in StringCollection are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); // Removing the first occurrence of // "A" from the StringCollection myCol.Remove("A"); Console.WriteLine("Elements in StringCollection are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); // Removing the first occurrence of // "C" from the StringCollection myCol.Remove("C"); Console.WriteLine("Elements in StringCollection are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); // Removing the first occurrence of // "A" from the StringCollection myCol.Remove("A"); Console.WriteLine("Elements in StringCollection are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); // Removing the first occurrence of // "Z" from the StringCollection // It would not throw exception even // if "Z" does not exist in myCol myCol.Remove("Z"); Console.WriteLine("Elements in StringCollection are : "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); } } Output: Elements in StringCollection are : A A A B C C D D E Elements in StringCollection are : A A B C C D D E Elements in StringCollection are : A A B C D D E Elements in StringCollection are : A B C D D E Elements in StringCollection are : A B C D D E Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.remove?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Remove the first occurrence from the StringCollection S Sahil_Bansall Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Specialized-Namespace CSharp-Specialized-StringCollection +1 More Similar Reads C# | Index of first occurrence in StringCollection StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.IndexOf(String) method is used to search the specified string which returns the ze 2 min read C# | Remove from the specified index of the StringCollection StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.RemoveAt(Int32) method is used to remove the string at the specified index of the 3 min read C# | Remove all the strings from the StringCollection StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.Clear method is used to remove all the strings from the StringCollection. Syntax: 2 min read C# | Remove the first occurrence of a specific object from the ArrayList ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Remove(Object) method is used to remove the first occurrence of a 3 min read C# | Check if the specified string is in the StringCollection StringCollection class is a new addition to the .NET Framework class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. StringCollection.Contains(String) method is used to check whether the specified string is in the St 2 min read Like