This documentation is archived and is not being maintained.

Hashtable Constructor (Int32, Single)

.NET Framework 1.1

Creates an empty Hashtable with the specified initial capacity and using the specified load factor, the default hash code provider and the default comparer.

[Visual Basic]
Public Sub New( _
   ByVal capacity As Integer, _
   ByVal loadFactor As Single _
public Hashtable(
   int capacity,
 float loadFactor
public: Hashtable(
   int capacity,
 float loadFactor
public function Hashtable(
   capacity : int,
 loadFactor : float


The approximate number of elements that the Hashtable can initially contain.
A number in the range from 0.1 through 1.0 indicating the maximum ratio of elements to buckets.


Exception Type Condition
ArgumentOutOfRangeException capacity is less than zero.


loadFactor is less than 0.1.


loadFactor is greater than 1.0.


Specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Hashtable. Capacity is automatically increased as required based on the load factor.

The load factor is the maximum ratio of elements to buckets. A smaller load factor means faster lookup at the cost of increased memory consumption. A load factor of 1.0 is the best balance between speed and size.

When the actual load factor reaches the load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

The hash code provider dispenses hash codes for keys in the Hashtable. The default hash code provider is the key's implementation of Object.GetHashCode.

The comparer determines whether two keys are equal. Every key in a Hashtable must be unique. The default comparer is the key's implementation of Object.Equals.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Hashtable Class | Hashtable Members | System.Collections Namespace | Hashtable Constructor Overload List | Object.GetHashCode | Object.Equals