2014.9.20hashtable Overview

Source: Internet
Author: User

Hashtable is a hash table used to represent a set of key values. These key-value pairs are organized based on the hash code of the key. Each element of the hashtable is stored in the key-value pair in the dictionaryentry object. The key cannot be a null reference.

Count: gets the number of key-value pairs contained in hashtable.

Isfixedsize: gets a value indicating whether the hashtable has a fixed size.

Isreadonly: gets a value indicating whether hashtable is read-only.

Issynchronized: gets a value indicating whether to synchronize access to hashtable.

Item: gets or sets the value associated with the specified key.

Keys: gets the icollection containing keys in hashtable.

Syncroot: Get the object that can be used to synchronize hashtable access

Values: Get the icollection containing hashtable

1. Add the hashtable Element

You can use the add method provided by hashtable.

Static void main (string [] ARGs)

{

Hashtable = new hashtable ();

Hashtable. Add ("ID", "bh001 ");

Hashtable. Add ("name", "TM ");

Hashtable. Add ("sex", "male ");

Console. writeline (hashtable. Count );

Console. Readline ();

}

2. Delete the hashtable Element

You can use the clear and remove methods.

3. Traverse hashtable

Hashtable traversal is similar to array traversal. However, the key-value pair is used to traverse elements in hashtable. The dictionaryentry type indicates the set of key-value pairs. For example:

Static void main (string [] ARGs)

{

Hashtable = new hashtable ();

Hashtable. Add ("ID", "hb001 ");

Hashtable. Add ("name", "TM ");

Hashtable. Add ("sex", "male ");

Console. writeline ("\ t key \ tvalue ");

Foreach (dictionaryentry dicentry in hashtable)

{

Console. writeline ("\ t" + dicentry. Key + "\ t" + dicentry. value );

}

Console. Readline ();

}

 

2014.9.20hashtable Overview

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.