Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Hashtable Constructor (IDictionary, Single, IHashCodeProvider, IComparer)

.NET Framework 1.1

Copies the elements from the specified dictionary to a new Hashtable with the same initial capacity as the number of elements copied and using the specified load factor, the specified hash code provider and the specified comparer.

[Visual Basic]
Public Sub New( _
   ByVal d As IDictionary, _
   ByVal loadFactor As Single, _
   ByVal hcp As IHashCodeProvider, _
   ByVal comparer As IComparer _
)
[C#]
public Hashtable(
   IDictionary d,
 float loadFactor,
 IHashCodeProvider hcp,
 IComparer comparer
);
[C++]
public: Hashtable(
   IDictionary* d,
 float loadFactor,
 IHashCodeProvider* hcp,
 IComparer* comparer
);
[JScript]
public function Hashtable(
   d : IDictionary,
 loadFactor : float,
 hcp : IHashCodeProvider,
 comparer : IComparer
);

Parameters

d
The IDictionary to copy to a new Hashtable.
loadFactor
A number in the range from 0.1 through 1.0 indicating the maximum ratio of elements to buckets.
hcp
The IHashCodeProvider that supplies the hash codes for all keys in the Hashtable.

-or-

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

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

-or-

A null reference (Nothing in Visual Basic) to use the default comparer, which is each key's implementation of Object.Equals.

Exceptions

Exception Type Condition
ArgumentNullException d is a null reference (Nothing in Visual Basic).
ArgumentOutOfRangeException loadFactor is less than 0.1.

-or-

loadFactor is greater than 1.0.

Remarks

The initial capacity is set to the number of elements in the source dictionary. 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.The custom hash code provider and the custom comparer enable such scenarios as doing lookups with case-insensitive strings.

The elements of the new Hashtable are sorted in the same order in which the enumerator iterates through the IDictionary.

Requirements

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

See Also

Hashtable Class | Hashtable Members | System.Collections Namespace | Hashtable Constructor Overload List

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.