Last Updated : 11 Jul, 2025
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.Specializednamespace.
StringCollection.Clearmethod is used to remove all the strings from the StringCollection.
Syntax:public void Clear ();Note:
// 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:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4