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 implementation in a better way:
Example 1:
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
OrderedDictionary myDict = new OrderedDictionary();
myDict.Add( "key1" , "value1" );
myDict.Add( "key2" , "value2" );
myDict.Add( "key3" , "value3" );
myDict.Add( "key4" , "value4" );
myDict.Add( "key5" , "value5" );
Console.WriteLine( "Number of key/value pairs are : "
+ myDict.Count);
}
}
|
Output:
Number of key/value pairs are : 5
Example 2:
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
public static void Main()
{
OrderedDictionary myDict = new OrderedDictionary();
myDict.Add( "A" , "Apple" );
myDict.Add( "B" , "Banana" );
myDict.Add( "C" , "Cat" );
myDict.Add( "D" , "Dog" );
Console.WriteLine( "Number of key/value pairs are : "
+ myDict.Count);
}
}
|
Output:
Number of key/value pairs are : 4
Reference: