本文整理汇总了C#中HashTable.Count方法的典型用法代码示例。如果您正苦于以下问题:C# HashTable.Count方法的具体用法?C# HashTable.Count怎么用?C# HashTable.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable.Count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/* Task 4:
* Implement the data structure "hash table" in a class HashTable<K,T>.
* Keep the data in array of lists of key-value pairs (LinkedList<KeyValuePair<K,T>>[])
* with initial capacity of 16. When the hash table load runs over 75%, perform resizing to 2
* times larger capacity. Implement the following methods and properties: Add(key, value), Find(key)value,
* Remove( key), Count, Clear(), this[], Keys. Try to make the hash table to support iterating over its elements
* with foreach.
*/
//Few functionalities are missing. If I have time I will add them as well.
static void Main(string[] args)
{
var hashTable = new HashTable<string, int>();
for (int i = 0; i < 100; i++)
{
hashTable.Add("Entri" + i, i);
}
Console.WriteLine(hashTable.Count());
Console.WriteLine(hashTable.Find("Entri50"));
for (int i = 50; i < 100; i++)
{
hashTable.Remove("Entri" + i);
}
//Will throw an exception
//Console.WriteLine(hashTable.Find("Entri50"));
var keys = hashTable.Keys();
foreach (var key in keys)
{
Console.WriteLine(key);
}
hashTable.Clear();
Console.WriteLine(hashTable.Count());
}
示例2: Main
static void Main()
{
HashTable<string, int> myPeopleAge = new HashTable<string, int>();
Console.WriteLine("MY PEOPLE");
myPeopleAge.Add("Siabonga", 20);
myPeopleAge.Add("Huren", 21);
myPeopleAge["Filip"] = 22;
myPeopleAge["Garo"] = 18;
Console.WriteLine("count="+ myPeopleAge.Count());
foreach (var item in myPeopleAge)
{
Console.WriteLine(item);
}
Console.WriteLine();
Console.WriteLine("MY PEOPLE AFTER REMOVE FILIP AND GARO");
myPeopleAge.Remove("Filip");
myPeopleAge.Remove("Garo");
Console.WriteLine("count="+myPeopleAge.Count());
foreach (var item in myPeopleAge)
{
Console.WriteLine(item);
}
Console.WriteLine();
Console.WriteLine("ONLY THE KEYS");
List<string> myKeys = myPeopleAge.Keys;
for (int i = 0; i < myKeys.Count; i++)
{
Console.WriteLine(myKeys[i]);
}
Console.WriteLine();
Console.Write("Find Siabonga age: ");
Console.Write(myPeopleAge.Find("Siabonga"));
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("AFTER CLEAR COMAND");
myPeopleAge.Clear();
Console.WriteLine("count="+myPeopleAge.Count());
Console.WriteLine();
//Console.Write("Find Oncho(I do not have Oncho) age: ");
//Console.Write(myPeopleAge.Find("Oncho"));
}