Hash Table是一種有key value的資料結構~
我們能在Hash Table中存入一個value然後將它對應到key~
其目的是為了~ 加快程式訪問value的速度(O(1))~
學習目標: Hash Table概念及實務
學習難度: ☆☆☆
namespace ConsoleApp1
{
class MainProgram
{
static void Main()
{
Hashtable hashtable = new Hashtable();
hashtable.Add("wilson", "student"); //wilson(key),student(value)
hashtable.Add("william", "student"); //wilson(key),student(value)
hashtable.Remove("william"); //remove key
Console.WriteLine(hashtable.ContainsKey("wilson")); //回傳true
Console.WriteLine(hashtable.ContainsValue("student")); //回傳true
foreach (DictionaryEntry tuple in hashtable)
{
Console.Write(tuple.Key + " ");
Console.Write(tuple.Value + "\n");
}
}
}
}
參考資料:
https://www.youtube.com/watch?v=s8YcbwVl-HI&ab_channel=RenaissanceCoders
https://www.geeksforgeeks.org/hashing-data-structure/