C# | Get the number of key/value pairs in the StringDictionary Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report StringDictionary.Count property is used to get the number of key/value pairs in the StringDictionary. Syntax: public virtual int Count { get; } Return Value: It returns the number of key/value pairs in the StringDictionary. Note: Retrieving the value of this property is an O(1) operation. Below programs illustrate the use of StringDictionary.Count property: Example 1: CSHARP // C# code to get the number of key/value // pairs in the StringDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a StringDictionary named myDict StringDictionary myDict = new StringDictionary(); // Getting the number of key/value // pairs in the StringDictionary Console.Write("Number of key/value pairs in myDict are : "); Console.WriteLine(myDict.Count); } } Output: Number of key/value pairs in myDict are : 0 Example 2: CSHARP // C# code to get the number of key/value // pairs in the StringDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a StringDictionary named myDict StringDictionary myDict = new StringDictionary(); // Adding key and value into the StringDictionary myDict.Add("G", "Geeks"); myDict.Add("F", "For"); myDict.Add("C", "C++"); myDict.Add("DS", "Data Structures"); myDict.Add("N", "Noida"); // Getting the number of key/value // pairs in the StringDictionary Console.Write("Number of key/value pairs in myDict are : "); Console.WriteLine(myDict.Count); } } Output: Number of key/value pairs in myDict are : 5 Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringdictionary.count?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Get a collection of values in the StringDictionary S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Collections-Namespace CSharp-Specialized-StringDictionary CSharp-Specialized-Namespace Similar Reads C# | Gets or sets the value at the specified key in StringDictionary StringDictionary.Item[String] Property is used to get or set the value associated with the specified key. Syntax: public virtual string this[string key] { get; set; } Here, key is the Key of type System.String whose value is be to get or set. Return Value: This property returns the value associated 3 min read C# | Get the number of key/values pairs contained in OrderedDictionary OrderedDictionary.Count property is used to get the number of key/values pairs contained in the OrderedDictionary collection. Syntax: public int Count { get; } Return Value: The number of key/value pairs contained in the OrderedDictionary collection. Below given are some examples to understand the i 2 min read C# | Get or set the value associated with the specified key in StringDictionary StringDictionary is a specialized collection. It is found in the System.Collections.Specialized namespace. It only allows string keys and string values. It suffers from performance problems. It implements a hash table with the key and the value strongly typed to be strings rather than objects. Below 2 min read C# | Get a collection of values in the StringDictionary StringDictionary.Values property is used to get a collection of values in the StringDictionary. Syntax: public virtual System.Collections.ICollection Values { get; } Return Value: An ICollection that provides the values in the StringDictionary. Example 1: CSHARP // C# code to get a collection // of 2 min read C# | Count the number of key/value pairs in the Hashtable The Hashtable class represents a collection of key-and-value pairs that are organized based on the hash code of the key. The key is used to access the items in the collection. Hashtable.Count Property is used to get the total number of the key/value pairs contained in the Hashtable. Syntax: myTable. 2 min read C# | Get the number of strings in 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.Count property is used to get the number of strings contained in the StringCollect 2 min read Like