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 implementation in a better way:
Example 1:
// 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); } } |
chevron_right
filter_none
Output:
Number of key/value pairs are : 5
Example 2:
// 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); } } |
chevron_right
filter_none
Output:
Number of key/value pairs are : 4
Reference:
Recommended Posts:
- C# | Get the number of key/value pairs contained in ListDictionary
- C# | Get the number of elements contained in Collection<T>
- C# | Get the number of nodes contained in LinkedList<T>
- C# | Get the number of elements actually contained in the ArrayList
- C# | Number of elements contained in the BitArray
- C# | Get the number of elements contained in the Queue
- C# | Get the number of elements contained in the Stack
- C# | Get the number of elements contained in SortedList
- C# | Check whether an element is contained in the ArrayList
- C# | OrderedDictionary Class
- C# | Add key and value into OrderedDictionary collection
- How to create an OrderedDictionary in C#
- C# | Get a read-only copy of the OrderedDictionary
- C# | Get an ICollection containing keys in OrderedDictionary
- C# | Remove entry with specified key from OrderedDictionary
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.



