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:
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
StringCollection myCol = new StringCollection();
String[] myArr = new String[] { "First" , "Second" , "Third" ,
"Fourth" , "Fifth" };
myCol.AddRange(myArr);
Console.WriteLine( "Number of strings in myCol are : " + myCol.Count);
}
}
|
Output:
Number of strings in myCol are : 5
Example 2:
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
StringCollection myCol = new StringCollection();
String[] myArr = new String[] {};
myCol.AddRange(myArr);
Console.WriteLine( "Number of strings in myCol are : "
+ myCol.Count);
}
}
|
Output:
Number of strings in myCol are : 0
Reference: