C # Hash Table

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.