A Common methods:
Hashtable hshtable = new Hashtable (); Create a hash table
Hshtable. ADD ("Person1", "ZHANGHF"); Add a key-value pair to the hash table
Hshtable. Clear (); Remove all key-value pairs from the hash table
Hshtable. Contains ("Person1"); Determines whether the hash table contains the key
String name = (string) hshtable["Person1"]. ToString (); Takes the value of the specified key in the hash table
Hshtable.remove ("Person1"); Deletes the key value pair for the specified key in the hash table
IDictionaryEnumerator en = Hshtable.getenumerator (); Iterate through all the keys of the hash table and read out the corresponding values
while (en. MoveNext ()) {
String str = en. Value.tostring ();
}
Two To traverse a hash table:
Traversing a hash table requires the use of DictionaryEntry Object, the code is as follows:
For (DictionaryEntry de in HT)//HT is a Hashtable instance {
Console.WriteLine (DE. Key);//de. Key corresponds to the Key/value key value pair key
Console.WriteLine (DE. Value);//de. Key corresponds to the value of the Key/value key
}
Or
foreach (Object key in Htriskmap.keys)
{
Console.WriteLine (key);
Console.WriteLine (Htriskmap[key]. ToString ());//htriskmap[key]. ToString () corresponds to the value of the Key/value key pair
}
C # Hash Table