How to create a StringCollection in C# Last Updated : 27 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: public StringCollection (); Example 1: csharp // C# Program to illustrate how // to create a StringCollection using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // sc is the StringCollection object // StringCollection() is the constructor // used to initializes a new // instance of the StringCollection class StringCollection sc = new StringCollection(); // Count property is used to get the // number of elements in StringCollection // It will give 0 as no elements // are present currently Console.WriteLine("Number of elements: "+ sc.Count); } } Output: Number of elements: 0 Example 2: csharp // C# Program to illustrate how // to create a StringCollection using System; using System.Collections; using System.Collections.Specialized; class Geeks { // Main Method public static void Main(String[] args) { // sc is the StringCollection object // StringCollection() is the constructor // used to initializes a new // instance of the StringCollection class StringCollection sc = new StringCollection(); Console.Write("Before Add Method: "); // Count property is used to get the // number of elements in StringCollection // It will give 0 as no elements // are present currently Console.WriteLine(sc.Count); Console.Write("After Add Method: "); // Adding elements in StringCollection sc.Add("A"); sc.Add("B"); sc.Add("C"); sc.Add("D"); sc.Add("E"); // Count property is used to get the // number of elements in ld Console.WriteLine(sc.Count); } } Output: Before Add Method: 0 After Add Method: 5 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.-ctor?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article How to create a StringCollection in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-StringCollection Similar Reads How to create a StringDictionary in C# StringDictionary() constructor is used to initialize a new instance of the StringDictionary class which will be empty and will have the default initial capacity. StringDictionary is a specialized collection. This class comes under the System.Collections.Specialized namespace. It only allows string k 2 min read How to create a ListDictionary in C# ListDictionary() constructor is used to initialize a new empty instance of the ListDictionary class using the default comparer. ListDictionary is a specialized collection. It comes under the System.Collections.Specialized namespace. This type represents a non-generic dictionary type. It is implement 2 min read How to create the StringBuilder in C# StringBuilder() constructor is used to initialize a new instance of the StringBuilder class which will be empty and will have the default initial capacity. StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutabl 2 min read How to create an OrderedDictionary in C# OrderedDictionary() constructor is used to initialize a new instance of the OrderedDictionary class which will be empty and will have the default initial capacity. OrderedDictionary Class represents a collection of key/value pairs that are accessible by the key or index. It is present in System.Coll 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# StringCollection Class In C#, the StringCollection class is part of the System.Collections.Specialized namespace. It provides a collection of strings that allows us to store and manage a list of strings easily. This class is a type-safe collection that automatically resizes as needed.StringCollection class accepts null as 5 min read How to Compare Strings in C#? A string is a collection of characters and is used to store plain text. Unlike C or C++, a string in C# is not terminated with a null character. The maximum size of a string object depends on the internal architecture of the system. A variable declared followed by "string" is actually an object of s 13 min read How to get Synchronize access to the StringCollection in C# StringCollection.SyncRoot Property is used to get an object which can be used to synchronize access to the StringCollection. This class library that represents a collection of strings. StringCollection class is defined in the System.Collections.Specialized namespace. Syntax: public virtual object Sy 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 Like