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