C # Hashtable of a set

Source: Internet
Author: User

1. HashTable Definition

System. collections. the Hashtable class indicates a set of key/value pairs. These key/value pairs are organized based on the hash code of the key. Each element is a key/value pair stored in the DictionaryEntry object. The key cannot be null, but the value can be.

2. Advantages

1. Quickly search by Key.

2,HashtableIs thread-safe.

3. Hashtable Constructor

Constructors

Note

Public Hashtable ()

Use the default initial capacity (size 0), load factor, hash code provider, and comparator to initializeHashtableClass.

Public Hashtable (IDictionary)

Copy the elements in the specified dictionary to the newHashtableObject, initializationHashtableClass. NewHashtableThe initial capacity of the object is equal to the number of copied elements, and the default loading factor, hash code provider, and comparator are used.

Public Hashtable (Int32)

Use the specified initial capacity, default load factor, default hash code provider, and default comparator to initializeHashtableClass.

4. Attributes of Hashtable

Attribute name

Note

Count

Obtain the number of key/value pairs contained in Hashtable.

IsFixedSize

Gets a value that indicates whether the Hashtable has a fixed size.

IsReadOnly

Gets a value indicating whether Hashtable is read-only.

Keys

Obtain the ICollection that contains keys in Hashtable.

Values

Obtain the ICollection that contains the values in Hashtable.

5. Hashtable Method

Method Name

Note

Void Add (object key, object value)

Add the elements with the specified key and value to Hashtable.

Void Clear ()

Remove all elements from Hashtable.

Bool Contains (object key)

Determine whether Hashtable contains a specific key.

Bool ContainsKey (object key)

Determine whether Hashtable contains a specific key.

Bool ContainsValue (object value)

Determine whether Hashtable contains a specific value.

Void Remove (object key)

Removes elements with the specified key from Hashtable.

Void InsertRange (int index, Icollection collec)

Used to add a batch of elements starting from the specified position.

Clone ()

Create a superficial copy of Hashtable.

GetObjectData ()

Implement the ISerializable interface and return the data required to serialize Hashtable.

 

6. Example of Hashtable

 

Code
 
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.