C# | Get the number of key/value pairs in the StringDictionary
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:
// 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); } } |
chevron_right
filter_none
Output:
Number of key/value pairs in myDict are : 0
Example 2:
// 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); } } |
chevron_right
filter_none
Output:
Number of key/value pairs in myDict are : 5
Reference:
Recommended Posts:
- C# | Add key and value into StringDictionary
- C# | Get or set the value associated with the specified key in StringDictionary
- C# | Gets or sets the value at the specified key in StringDictionary
- C# | StringDictionary Class
- How to create a StringDictionary in C#
- C# | Get a collection of values in the StringDictionary
- C# | Check if the StringDictionary contains a specific value
- C# | Removing all entries from the StringDictionary
- C# | Get a collection of keys in the StringDictionary
- How to get Synchronize access to the StringDictionary in C#
- C# | Check if the StringDictionary contains a specific key
- C# | Remove entry with specified key from the StringDictionary
- C# | Get an enumerator that iterates through the stringDictionary
- C# | Check if two StringDictionary objects are equal or not
- C# | Copy StringDictionary to Array at the specified index
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



