C# | Remove all the strings 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.Clear method is used to remove all the strings from the StringCollection. Syntax: public void Clear (); Note: Count is set to zero, and references to other objects from elements of the collection are also released. This method is an O(n) operation, where n is Count. Example: CSHARP // C# code to insert a string into // the StringCollection at the // specified index 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[] {"Hello", "Geeks", "for", "GeeksforGeeks"}; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); Console.WriteLine("Initially elements in StringCollection are: "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); // Removing all the elements from StringCollection myCol.Clear(); Console.WriteLine("After Removing: "); // Displaying elements in StringCollection // named myCol foreach(Object obj in myCol) Console.WriteLine(obj); } } Output: Initially elements in StringCollection are: Hello Geeks for GeeksforGeeks After Removing: Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.clear?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Remove all the strings 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# | Remove the first occurrence 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.Remove(String) method is used to remove the first occurrence of a specific string 3 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# | Get the number of strings 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.Count property is used to get the number of strings contained in the StringCollect 2 min read C# | Removing all entries from the StringDictionary StringDictionary.Clear method is used to remove all the entries from the StringDictionary. Syntax: public virtual void Clear (); Exception: This method will give the NotSupportedException if the StringDictionary is read-only. Example: CSHARP // C# code to remove all entries // from the StringDiction 2 min read C# | Add a string to the end 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.Add(String) Method is used to add a string to the end of the StringCollection. Syn 2 min read C# | Check if the StringCollection is read-only 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.IsReadOnly property is used to get a value indicating whether the StringCollection 1 min read C# | Removing all the elements from the List List class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace. List class can be used to create a collection of different types like integers, strings etc. List class also provides the methods to search, sort, and manipulate lists. L 3 min read C# | Remove entry with specified key from the StringDictionary StringDictionary.Remove(String) method is used to remove the entry with the specified key from the string dictionary. Syntax: public virtual void Remove (string key); Here, key is the key of the entry to remove. Exceptions: ArgumentNullException: If the key is null. NotSupportedException: If the Str 3 min read How to create a StringCollection in C# StringCollection() constructor is used to initializing a new instance of the StringCollection class. 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 2 min read C# | Remove all elements from the SortedSet SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Clear Method is used to remove the all elements from the SortedSet. Properties: In C#, SortedSet class can be used to store, remove or view elements. 2 min read Like