.NET API Documentation

Hashtable Class

Summary

Represents a collection of key-and-value pairs that are organized based on the hash code of the keys. This class cannot be inherited.

public sealed class Hashtable : IDictionary, ICollection, IEnumerable, ICloneable

Constructors

Hashtable()

public Hashtable()

Initializes a new instance of the Hashtable class that is empty, has the default initial capacity, and uses the default hash table implementation.

Hashtable(IDictionary dictionary)

public Hashtable(IDictionary dictionary)

Initializes a new instance of the Hashtable class that contains elements copied from the specified IDictionary and that has sufficient capacity to accommodate the number of elements copied.

Hashtable(int capacity)

public Hashtable(int capacity)

Initializes a new instance of the Hashtable class that is empty, has the specified initial capacity, and uses the default hash table implementation.

Hashtable(int capacity, float loadFactor)

public Hashtable(int capacity, float loadFactor)

Initializes a new instance of the Hashtable class that is empty, has the specified initial capacity, and uses the specified load factor.

Hashtable(int capacity, float loadFactor, IHashCodeProvider hcp, IComparer comparer)

public Hashtable(int capacity, float loadFactor, IHashCodeProvider hcp, IComparer comparer)

Initializes a new instance of the Hashtable class with the specified initial capacity, load factor, hash code provider, and comparer.

Properties

Count

public virtual int Count { get; }

Gets the number of key-and-value pairs contained in the Hashtable.

IsFixedSize

public virtual bool IsFixedSize { get; }

Gets a value indicating whether the Hashtable has a fixed size.

IsReadOnly

public virtual bool IsReadOnly { get; }

Gets a value indicating whether the Hashtable is read-only.

IsSynchronized

public virtual bool IsSynchronized { get; }

Gets a value indicating whether access to the Hashtable is synchronized (thread-safe).

Keys

public virtual ICollection Keys { get; }

Gets an ICollection containing the keys in the Hashtable.

Values

public virtual ICollection Values { get; }

Gets an ICollection containing the values in the Hashtable.

SyncRoot

public virtual object SyncRoot { get; }

Gets an object that can be used to synchronize access to the Hashtable.

Methods

Add(object key, object value)

public virtual void Add(object key, object value)

Adds an element with the specified key and value to the Hashtable.

// Example Usage:
Hashtable myTable = new Hashtable();
myTable.Add("myKey", "myValue");

Clear()

public virtual void Clear()

Removes all elements from the Hashtable.

Clone()

public virtual object Clone()

Creates a shallow copy of the Hashtable.

Contains(object key)

public virtual bool Contains(object key)

Determines whether the Hashtable contains a specific key.

ContainsKey(object key)

public virtual bool ContainsKey(object key)

Determines whether the Hashtable contains a specific key.

ContainsValue(object value)

public virtual bool ContainsValue(object value)

Determines whether the Hashtable contains a specific value.

GetEnumerator()

public virtual IDictionaryEnumerator GetEnumerator()

Returns an IDictionaryEnumerator that iterates through the Hashtable.

Remove(object key)

public virtual void Remove(object key)

Removes the element with the specified key from the Hashtable.