Skip to content
Related Articles

Related Articles

Improve Article

C# | Remove all the strings from the StringCollection

  • Last Updated : 01 Feb, 2019

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.


public void Clear ();


  • 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.


// 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.
        Console.WriteLine("Initially elements in StringCollection are: ");
        // Displaying elements in StringCollection
        // named myCol
        foreach(Object obj in myCol)
        // Removing all the elements from StringCollection
        Console.WriteLine("After Removing: ");
        // Displaying elements in StringCollection
        // named myCol
        foreach(Object obj in myCol)
Initially elements in StringCollection are: 
After Removing:


My Personal Notes arrow_drop_up
Recommended Articles
Page :