NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Hashtable Constructor (Int32, IHashCodeProvider, IComparer)

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

[Visual Basic]
Overloads Public Sub New( _
   ByVal capacity As Integer, _
   ByVal hcp As IHashCodeProvider, _
   ByVal comparer As IComparer _
)
[C#]
public Hashtable(
   int capacity,
   IHashCodeProvider hcp,
   IComparer comparer
);
[C++]
public: Hashtable(
   int capacity,
   IHashCodeProvider* hcp,
   IComparer* comparer
);
[JScript]
public function Hashtable(
   capacity : int,
   hcp : IHashCodeProvider,
   comparer : IComparer
);

Parameters

capacity
The initial number of entries that the Hashtable can contain.
hcp
The IHashCodeProvider that will supply the hash codes for all keys in the Hashtable.

-or-

a null reference (in Visual Basic Nothing) to use the default hash code provider, which is each key's implementation of GetHashCode.

comparer
The IComparer to use to determine whether two keys are equal.

-or-

a null reference (Nothing) to use the default comparer, which is each key's implementation of Equals.

Remarks

Specifying the initial capacity eliminates a number of resizing operations that would otherwise be performed while adding entries to the Hashtable. Capacity is increased as the number of buckets is increased based on the load factor.

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

When the actual load factor reaches the maximum 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 GetHashCode.

The comparer is used to determine if two keys are equal. Every key in a Hashtable must be unique. The default comparer is the key's implementation of Equals.

The custom hash code provider and the custom comparer enables scenarios such as doing lookups with case-insensitive strings.

See Also

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