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:
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
StringDictionary myDict = new 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:
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
StringDictionary myDict = new StringDictionary();
myDict.Add( "G" , "Geeks" );
myDict.Add( "F" , "For" );
myDict.Add( "C" , "C++" );
myDict.Add( "DS" , "Data Structures" );
myDict.Add( "N" , "Noida" );
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:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
01 Feb, 2019
Like Article
Save Article