C# | Get the number of key/values pairs contained in OrderedDictionary Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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: CSHARP // C# code to get the number of // key/values pairs contained // in the OrderedDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver method public static void Main() { // Creating a orderedDictionary named myDict OrderedDictionary myDict = new OrderedDictionary(); // Adding key and value in myDict myDict.Add("key1", "value1"); myDict.Add("key2", "value2"); myDict.Add("key3", "value3"); myDict.Add("key4", "value4"); myDict.Add("key5", "value5"); // To Get the number of key/values // pairs contained in the OrderedDictionary Console.WriteLine("Number of key/value pairs are : " + myDict.Count); } } Output: Number of key/value pairs are : 5 Example 2: CSHARP // C# code to get the number of // key/values pairs contained // in the OrderedDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver method public static void Main() { // Creating a orderedDictionary named myDict OrderedDictionary myDict = new OrderedDictionary(); // Adding key and value in myDict myDict.Add("A", "Apple"); myDict.Add("B", "Banana"); myDict.Add("C", "Cat"); myDict.Add("D", "Dog"); // To Get the number of key/values // pairs contained in the OrderedDictionary Console.WriteLine("Number of key/value pairs are : " + myDict.Count); } } Output: Number of key/value pairs are : 4 Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.ordereddictionary.count?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Get the number of key/value pairs contained in ListDictionary S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-OrderedDictionary Similar Reads C# | Get the number of key/value pairs contained in ListDictionary ListDictionary.Count property is used to get the number of key/value pairs contained in the ListDictionary. Syntax: public int Count { get; } Return Value : The number of key/value pairs contained in the ListDictionary. Below are the programs to illustrate the use of ListDictionary.Count property: E 2 min read 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 prog 2 min read C# | Count the number of key/value pairs in HybridDictionary HybridDictionary.Count property is used to get the number of key/value pairs contained in the HybridDictionary. Syntax: public int Count { get; } Return Value: The number of key/value pairs contained in the HybridDictionary. Note: Retrieving the value of this property is an O(1) operation. Below pro 2 min read C# | Get an ICollection containing values in OrderedDictionary OrderedDictionary.Values property is used to get an ICollection object containing the values in the OrderedDictionary collection. Syntax: public System.Collections.ICollection Values { get; } Return Value: It returns an ICollection object containing the values in the OrderedDictionary collection. Be 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 elements contained in SortedList SortedList.Count Property is used to get the number of elements contained in a SortedList object. Syntax: public virtual int Count { get; } Property Value: The number of elements contained in the SortedList object. Below programs illustrate the use of above discussed method: Example 1: CSharp // C# 2 min read Like