C# |计算混合字典
中键/值对的数量
原文:https://www . geesforgeks . org/c-sharp-count-number-of-key-value-pairs-in-hybrid dictionary/
杂交词典。Count 属性用于获取混合字典中包含的键/值对的数量。
语法:
public int Count { get; }
返回值:混合字典中包含的键/值对的数量。
注意:检索该属性的值是一个 O(1)运算。
以下程序说明了混合词典的使用。计数属性:
例 1:
// C# code to get the number of key/value
// pairs contained in the HybridDictionary.
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
// Driver code
public static void Main()
{
// Creating a HybridDictionary named myDict
HybridDictionary myDict = new HybridDictionary();
// 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);
}
}
输出:
Total key/value pairs in myDict are : 6
例 2:
// C# code to get the number of key/value
// pairs contained in the HybridDictionary.
using System;
using System.Collections;
using System.Collections.Specialized;
class GFG {
// Driver code
public static void Main()
{
// Creating a HybridDictionary named myDict
HybridDictionary myDict = new HybridDictionary();
// 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");
// To get count of key/value pairs in myDict
Console.WriteLine("Total key/value pairs in myDict are : "
+ myDict.Count);
}
}
输出:
Total key/value pairs in myDict are : 5
参考:
版权属于:月萌API www.moonapi.com,转载请注明出处