C# | Dictionary.Count Property Last Updated : 01 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report This property is used to get the number of key/value pairs contained in the Dictionary. Syntax: public int Count { get; } Return Value : The number of key/value pairs contained in the Dictionary. Below are the programs to illustrate the use of above-discussed property: Example 1: csharp // C# code to count the number of // key/value pairs in Dictionary using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Create a new dictionary of // strings, with string keys. Dictionary<string, string> myDict = new Dictionary<string, string>(); // 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"); // To get count of key/value // pairs in myDict Console.WriteLine("Total key/value pairs"+ " in myDict are : " + myDict.Count); } } Output: Total key/value pairs in myDict are : 6 Example 2: csharp // C# code to count the number of // key/value pairs in Dictionary using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Create a new dictionary of // strings, with string keys. Dictionary<int, string> myDict = new Dictionary<int, string>(); // Adding key/value pairs in myDict myDict.Add(1, "C"); myDict.Add(2, "C++"); myDict.Add(3, "Java"); myDict.Add(4, "Python"); myDict.Add(5, "C#"); myDict.Add(6, "HTML"); // To get count of key/value pairs in myDict Console.WriteLine("Total key/value pairs"+ " in myDict are : " + myDict.Count); } } Output: Total key/value pairs in myDict are : 6 Note: Retrieving the value of this property is an O(1) operation. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.count?view=netframework-4.7.2#System_Collections_Generic_Dictionary_2_Count Comment More infoAdvertise with us Next Article C# | Dictionary.Count Property R rupesh_rao Follow Improve Article Tags : C# CSharp-Generic-Namespace CSharp Dictionary Class Similar Reads C# | Dictionary.Keys Property This property is used to get a collection containing the keys in the Dictionary. Syntax: public System.Collections.Generic.Dictionary<TKey, TValue>.KeyCollection Keys { get; } Return Value : It returns a collection containing the keys in the Dictionary. Below are the programs to illustrate the 2 min read C# | Dictionary.Item[] Property This property is used to get or set the value associated with the specified key in the Dictionary. Syntax: public TValue this[TKey key] { get; set; } Here, key is the Key of the value to get or set. Property Value: It is the value associated with the specified key. If the specified key is not found, 2 min read C# | Dictionary.Values Property This property is used to get a collection containing the values in the Dictionary<TKey,TValue>. Syntax: public System.Collections.Generic.Dictionary<TKey, TValue>.KeyCollection Values{ get; } Return Value: This property returns a collection containing the Values in the Dictionary. Below 2 min read Queue.Count Property in C# This property is used to get the number of elements contained in the Queue. Retrieving the value of this property is an O(1) operation and it comes under the System.Collections namespace. Syntax: public virtual int Count { get; } Property Value: This property returns the number of elements contained 2 min read Stack.Count Property in C# This method(comes under System.Collections namespace) is used to get the number of elements contained in the Stack. The capacity is the number of elements that the Stack can store and the count is the number of elements that are actually in the Stack. The capacity is always greater than or equal to 2 min read Like