C# | Get the number of key/value pairs contained in ListDictionary Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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: Example 1: CSHARP // C# code to get the number // of key/value pairs contained // in the ListDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a ListDictionary named myDict ListDictionary myDict = new ListDictionary(); // Adding key/value pairs in myDict myDict.Add("Australia", "Canberra"); myDict.Add("Belgium", "Brussels"); myDict.Add("Netherlands", "Amsterdam"); myDict.Add("China", "Beijing"); myDict.Add("Russia", "Moscow"); myDict.Add("India", "New Delhi"); // Displaying the number of key/value // pairs contained in the ListDictionary Console.WriteLine(myDict.Count); } } Output: 6 Example 2: CSHARP // C# code to get the number // of key/value pairs contained // in the ListDictionary using System; using System.Collections; using System.Collections.Specialized; class GFG { // Driver code public static void Main() { // Creating a ListDictionary named myDict ListDictionary myDict = new ListDictionary(); // Adding key/value pairs in myDict myDict.Add("I", "first"); myDict.Add("II", "second"); myDict.Add("III", "third"); myDict.Add("IV", "fourth"); myDict.Add("V", "fifth"); // Displaying the number of key/value // pairs contained in the ListDictionary Console.WriteLine(myDict.Count); } } Output: 5 Note: Retrieving the value of this property is an O(1) operation. Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.listdictionary.count?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Count the number of key/value pairs in HybridDictionary S Sahil_Bansall Follow Improve Article Tags : C# CSharp-Specialized-Namespace CSharp-Specialized-ListDictionary Similar Reads 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 i 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# | 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 or set the value associated with specified key in ListDictionary ListDictionary.Item[Object] property is used to get or set the value associated with the specified key. Syntax: public object this[object key] { get; set; } Here, key is the key whose value to get or set. Return Value : The value associated with the specified key. If the specified key is not found, 2 min read C# | Add the specified key and value into the ListDictionary ListDictionary.Add(Object, Object) method is used to add an entry with the specified key and value into the ListDictionary. Syntax: public void Add (object key, object value); Parameters: key : The key of the entry to add. value : The value of the entry to add. The value can be null. Exceptions: Arg 2 min read C# | Get an ICollection containing the values in ListDictionary ListDictionary.Values property is used to get an ICollection containing the values in the ListDictionary. Syntax: public System.Collections.ICollection Values { get; } Return Value : It returns an ICollection containing the values in the ListDictionary. Below are the programs to illustrate the use o 2 min read Like