C# | Get the number of strings in StringCollection Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue 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.Count property is used to get the number of strings contained in the StringCollection. Syntax: public int Count { get; } Return Value: It returns the number of strings contained in the StringCollection. Note: Retrieving the value of this property is an O(1) operation. Below programs illustrate the use of StringCollection.Count Property: Example 1: // C# code to get the number of strings // contained in 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[] { "First", "Second", "Third", "Fourth", "Fifth" }; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // To get number of Strings contained // in the StringCollection Console.WriteLine("Number of strings in myCol are : " + myCol.Count); } } Output: Number of strings in myCol are : 5 Example 2: // C# code to get the number of strings // contained in 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[] {}; // Copying the elements of a string // array to the end of the StringCollection. myCol.AddRange(myArr); // To get number of Strings contained // in the StringCollection Console.WriteLine("Number of strings in myCol are : " + myCol.Count); } } Output: Number of strings in myCol are : 0 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringcollection.count?view=netframework-4.7.2 Last Updated : 01 Feb, 2019 Like Article Save Article Previous C# | StringDictionary Class Next C# | Add a string to the end of the StringCollection Share your thoughts in the comments Add Your Comment Please Login to comment...