Hashtable Hashtable Hashtable Hashtable Constructors

정의

오버로드

Hashtable() Hashtable() Hashtable()

기본 초기 용량, 로드 비율, 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the default initial capacity, load factor, hash code provider, and comparer.

Hashtable(Int32, Single, IHashCodeProvider, IComparer) Hashtable(Int32, Single, IHashCodeProvider, IComparer) Hashtable(Int32, Single, IHashCodeProvider, IComparer) Hashtable(Int32, Single, IHashCodeProvider, IComparer)

지정된 초기 용량, 로드 비율, 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, load factor, hash code provider, and comparer.

Hashtable(IDictionary, Single, IHashCodeProvider, IComparer) Hashtable(IDictionary, Single, IHashCodeProvider, IComparer) Hashtable(IDictionary, Single, IHashCodeProvider, IComparer) Hashtable(IDictionary, Single, IHashCodeProvider, IComparer)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 지정된 로드 비율, 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor, hash code provider, and comparer.

Hashtable(Int32, Single, IEqualityComparer) Hashtable(Int32, Single, IEqualityComparer) Hashtable(Int32, Single, IEqualityComparer) Hashtable(Int32, Single, IEqualityComparer)

지정된 초기 용량, 로드 비율 및 Hashtable 개체를 사용하여 IEqualityComparer 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, load factor, and IEqualityComparer object.

Hashtable(Int32, IHashCodeProvider, IComparer) Hashtable(Int32, IHashCodeProvider, IComparer) Hashtable(Int32, IHashCodeProvider, IComparer) Hashtable(Int32, IHashCodeProvider, IComparer)

지정된 초기 용량, 해시 코드 공급자 및 비교자와 기본 로드 비율을 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, hash code provider, comparer, and the default load factor.

Hashtable(IDictionary, Single, IEqualityComparer) Hashtable(IDictionary, Single, IEqualityComparer) Hashtable(IDictionary, Single, IEqualityComparer) Hashtable(IDictionary, Single, IEqualityComparer)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 지정된 로드 비율 및 IEqualityComparer 개체를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor and IEqualityComparer object.

Hashtable(IDictionary, IHashCodeProvider, IComparer) Hashtable(IDictionary, IHashCodeProvider, IComparer) Hashtable(IDictionary, IHashCodeProvider, IComparer) Hashtable(IDictionary, IHashCodeProvider, IComparer)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 기본 로드 비율과 지정된 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor, and the specified hash code provider and comparer. 이 API는 사용되지 않습니다.This API is obsolete. 다른 방법을 보려면 Hashtable(IDictionary, IEqualityComparer)를 참조하십시오.For an alternative, see Hashtable(IDictionary, IEqualityComparer).

Hashtable(Int32, Single) Hashtable(Int32, Single) Hashtable(Int32, Single) Hashtable(Int32, Single)

지정된 초기 용량 및 로드 비율과 기본 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity and load factor, and the default hash code provider and comparer.

Hashtable(SerializationInfo, StreamingContext) Hashtable(SerializationInfo, StreamingContext) Hashtable(SerializationInfo, StreamingContext) Hashtable(SerializationInfo, StreamingContext)

지정된 HashtableSerializationInfo 개체를 사용하여 serialize할 수 있는 StreamingContext 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class that is serializable using the specified SerializationInfo and StreamingContext objects.

Hashtable(IHashCodeProvider, IComparer) Hashtable(IHashCodeProvider, IComparer) Hashtable(IHashCodeProvider, IComparer) Hashtable(IHashCodeProvider, IComparer)

기본 초기 용량 및 로드 비율과 지정된 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor, and the specified hash code provider and comparer.

Hashtable(IDictionary, Single) Hashtable(IDictionary, Single) Hashtable(IDictionary, Single) Hashtable(IDictionary, Single)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 지정된 로드 비율과 기본 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor, and the default hash code provider and comparer.

Hashtable(IDictionary, IEqualityComparer) Hashtable(IDictionary, IEqualityComparer) Hashtable(IDictionary, IEqualityComparer) Hashtable(IDictionary, IEqualityComparer)

지정된 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to a new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 기본 로드 비율과 지정된 IEqualityComparer 개체를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor and the specified IEqualityComparer object.

Hashtable(Int32) Hashtable(Int32) Hashtable(Int32) Hashtable(Int32)

지정된 초기 용량과 기본 로드 비율, 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, and the default load factor, hash code provider, and comparer.

Hashtable(IEqualityComparer) Hashtable(IEqualityComparer) Hashtable(IEqualityComparer) Hashtable(IEqualityComparer)

기본 초기 용량 및 로드 비율과 지정된 Hashtable 개체를 사용하여 IEqualityComparer 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor, and the specified IEqualityComparer object.

Hashtable(IDictionary) Hashtable(IDictionary) Hashtable(IDictionary) Hashtable(IDictionary)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 기본 로드 비율, 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor, hash code provider, and comparer.

Hashtable(Int32, IEqualityComparer) Hashtable(Int32, IEqualityComparer) Hashtable(Int32, IEqualityComparer) Hashtable(Int32, IEqualityComparer)

지정된 초기 용량 및 Hashtable와 기본 로드 비율을 사용하여 IEqualityComparer 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity and IEqualityComparer, and the default load factor.

Hashtable() Hashtable() Hashtable()

기본 초기 용량, 로드 비율, 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the default initial capacity, load factor, hash code provider, and comparer.

public:
 Hashtable();
public Hashtable ();
Public Sub New ()

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myComparer : IEqualityComparer
{
public:
    virtual bool Equals(Object^ x, Object^ y) 
    {
        return x->Equals(y);
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

ref class myCultureComparer : IEqualityComparer
{
private:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

    virtual bool Equals(Object^ x, Object^ y) 
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

int main()
{
   
   // Create a hash table using the default hash code provider and the default comparer.
   Hashtable^ myHT1 = gcnew Hashtable((IEqualityComparer^)nullptr);
   myHT1->Add( "FIRST", "Hello" );
   myHT1->Add( "SECOND", "World" );
   myHT1->Add( "THIRD", "!" );
   
   // Create a hash table using the specified IEqualityComparer that uses
   // the default Object.Equals to determine equality.
   Hashtable^ myHT2 = gcnew Hashtable(gcnew myComparer());
   myHT2->Add( "FIRST", "Hello" );
   myHT2->Add( "SECOND", "World" );
   myHT2->Add( "THIRD", "!" );
   
   // Create a hash table using a case-insensitive hash code provider and
   // case-insensitive comparer based on the InvariantCulture.
   Hashtable^ myHT3 = gcnew Hashtable(
            CaseInsensitiveHashCodeProvider::DefaultInvariant,
            CaseInsensitiveComparer::DefaultInvariant);
   myHT3->Add( "FIRST", "Hello" );
   myHT3->Add( "SECOND", "World" );
   myHT3->Add( "THIRD", "!" );
   
   // Create a hash table using an IEqualityComparer that is based on
   // the Turkish culture (tr-TR) where "I" is not the uppercase
   // version of "i".
   CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
   Hashtable^ myHT4 = gcnew Hashtable( gcnew myCultureComparer(myCul) );
   myHT4->Add( "FIRST", "Hello" );
   myHT4->Add( "SECOND", "World" );
   myHT4->Add( "THIRD", "!" );
   
   // Search for a key in each hash table.
   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey( "first" ) );
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/
using System;
using System.Collections;
using System.Globalization;

class myComparer : IEqualityComparer
{
    public new bool Equals(object x, object y)
    {
        return x.Equals(y);
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable();
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the default Object.Equals to determine equality.
        Hashtable myHT2 = new Hashtable(new myComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using a case-insensitive hash code provider and
        // case-insensitive comparer based on the InvariantCulture.
        Hashtable myHT3 = new Hashtable(
            CaseInsensitiveHashCodeProvider.DefaultInvariant,
            CaseInsensitiveComparer.DefaultInvariant);
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT4 = new Hashtable(new myCultureComparer(myCul));
        myHT4.Add("FIRST", "Hello");
        myHT4.Add("SECOND", "World");
        myHT4.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));
        Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myComparer
    Implements IEqualityComparer
    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        Return x.Equals(y)
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode

        Return obj.ToString().ToLower().GetHashCode()
    End Function

End Class

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New Hashtable()
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer that uses
        ' the default Object.Equals to determine equality.
        Dim myHT2 As New Hashtable(New myComparer())
        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using a case-insensitive hash code provider and
        ' case-insensitive comparer based on the InvariantCulture.
        Dim myHT3 As New Hashtable( _
            CaseInsensitiveHashCodeProvider.DefaultInvariant, _
            CaseInsensitiveComparer.DefaultInvariant)
        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based on
        ' the Turkish culture (tr-TR) where "I" is not the uppercase
        ' version of "i".
        Dim myCul As New CultureInfo("tr-TR")
        Dim myHT4 As New Hashtable(New myCultureComparer(myCul))
        myHT4.Add("FIRST", "Hello")
        myHT4.Add("SECOND", "World")
        myHT4.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))
        Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first"))

    End Sub

End Class

'This code produces the following output.
'Results vary depending on the system's culture settings.

'first is in myHT1: False
'first is in myHT2: False
'first is in myHT3: True
'first is in myHT4: False

설명

해시 테이블의 용량 최적의 부하 비율에 따라 해시 테이블 버킷 수를 계산 하는 데 사용 됩니다.A hash table's capacity is used to calculate the optimal number of hash table buckets based on the load factor. 용량 자동으로 증가 해야 하는 경우.Capacity is automatically increased as required.

로드 비율에 버킷과 요소의 최대 비율입니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable 개체입니다.The hash code provider dispenses hash codes for keys in the Hashtable object. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

이 생성자는 o (1) 작업입니다.This constructor is an O(1) operation.

추가 정보

Hashtable(Int32, Single, IHashCodeProvider, IComparer) Hashtable(Int32, Single, IHashCodeProvider, IComparer) Hashtable(Int32, Single, IHashCodeProvider, IComparer) Hashtable(Int32, Single, IHashCodeProvider, IComparer)

경고

이 API는 현재 사용되지 않습니다.

지정된 초기 용량, 로드 비율, 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, load factor, hash code provider, and comparer.

public:
 Hashtable(int capacity, float loadFactor, System::Collections::IHashCodeProvider ^ hcp, System::Collections::IComparer ^ comparer);
[System.Obsolete("Please use Hashtable(int, float, IEqualityComparer) instead.")]
public Hashtable (int capacity, float loadFactor, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer);
new System.Collections.Hashtable : int * single * System.Collections.IHashCodeProvider * System.Collections.IComparer -> System.Collections.Hashtable
Public Sub New (capacity As Integer, loadFactor As Single, hcp As IHashCodeProvider, comparer As IComparer)

매개 변수

capacity
Int32 Int32 Int32 Int32

Hashtable 개체가 처음에 포함할 수 있는 대략적인 요소 수입니다.The approximate number of elements that the Hashtable object can initially contain.

loadFactor
Single Single Single Single

최고의 성능을 제공하는 기본값으로 곱한 0.1에서 1.0 사이의 수입니다.A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. 결과는 버킷과 요소의 최대 비율입니다.The result is the maximum ratio of elements to buckets.

hcp
IHashCodeProvider IHashCodeProvider IHashCodeProvider IHashCodeProvider

IHashCodeProvider의 모든 키에 해시 코드를 제공하는 Hashtable 개체입니다.The IHashCodeProvider object that supplies the hash codes for all keys in the Hashtable.

또는-or- 각 키의 GetHashCode() 구현인 기본 해시 코드 공급자를 사용하면 null입니다.null to use the default hash code provider, which is each key's implementation of GetHashCode().

comparer
IComparer IComparer IComparer IComparer

두 키가 같은지 여부를 확인하는 데 사용할 IComparer 개체입니다.The IComparer object to use to determine whether two keys are equal.

또는-or- 각 키로 Equals(Object)를 구현한 기본 비교자를 사용하면 null입니다.null to use the default comparer, which is each key's implementation of Equals(Object).

예외

capacity가 0보다 작은 경우capacity is less than zero.

또는-or- loadFactor가 0.1보다 작습니다.loadFactor is less than 0.1.

또는-or- loadFactor가 1.0보다 큽니다.loadFactor is greater than 1.0.

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(3, .8f);
        myHT1->Add("FIRST", "Hello");
        myHT1->Add("SECOND", "World");
        myHT1->Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(3, .8f, gcnew myCultureComparer());
        myHT2->Add("FIRST", "Hello");
        myHT2->Add("SECOND", "World");
        myHT2->Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(3, .8f, gcnew myCultureComparer(myCul));
        myHT3->Add("FIRST", "Hello");
        myHT3->Add("SECOND", "World");
        myHT3->Add("THIRD", "!");

        // Search for a key in each hash table.
		Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));

	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3, .8f);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(3, .8f, new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, .8f, new myCultureComparer(myCul));

        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New Hashtable(3, System.Convert.ToSingle(0.8))
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer that uses
        ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Dim myHT2 As New Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer())

        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based on
        ' the Turkish culture (tr-TR) where "I" is not the uppercase
        ' version of "i".
        Dim myCul As New CultureInfo("tr-TR")
        Dim myHT3 As New Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer(myCul))

        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

    End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

여러 요소를 추가 하는 동안 크기 조정 작업을 수행할 필요가 없습니다 초기 용량을 지정 하는 Hashtable 개체입니다.Specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Hashtable object. 용량을 자동으로 부하 비율에 따라 필요에 따라 증가 합니다.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. 1.0의 로드 비율을은 적절 한 속도와 크기입니다.A load factor of 1.0 is the best balance between speed and size.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

사용자 지정 해시 코드 공급자 및 사용자 지정 비교자를 대/소문자 문자열을 사용 하 여 조회를 수행 하는 등의 시나리오를 사용 하도록 설정 합니다.The custom hash code provider and the custom comparer enable scenarios such as doing lookups with case-insensitive strings.

이 생성자는 (n) 작업, 여기서 ncapacity 매개 변수입니다.This constructor is an O(n) operation, where n is the capacity parameter.

추가 정보

Hashtable(IDictionary, Single, IHashCodeProvider, IComparer) Hashtable(IDictionary, Single, IHashCodeProvider, IComparer) Hashtable(IDictionary, Single, IHashCodeProvider, IComparer) Hashtable(IDictionary, Single, IHashCodeProvider, IComparer)

경고

이 API는 현재 사용되지 않습니다.

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 지정된 로드 비율, 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor, hash code provider, and comparer.

public:
 Hashtable(System::Collections::IDictionary ^ d, float loadFactor, System::Collections::IHashCodeProvider ^ hcp, System::Collections::IComparer ^ comparer);
[System.Obsolete("Please use Hashtable(IDictionary, float, IEqualityComparer) instead.")]
public Hashtable (System.Collections.IDictionary d, float loadFactor, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer);
new System.Collections.Hashtable : System.Collections.IDictionary * single * System.Collections.IHashCodeProvider * System.Collections.IComparer -> System.Collections.Hashtable
Public Sub New (d As IDictionary, loadFactor As Single, hcp As IHashCodeProvider, comparer As IComparer)

매개 변수

d
IDictionary IDictionary IDictionary IDictionary

IDictionary 개체로 복사할 Hashtable 개체입니다.The IDictionary object to copy to a new Hashtable object.

loadFactor
Single Single Single Single

최고의 성능을 제공하는 기본값으로 곱한 0.1에서 1.0 사이의 수입니다.A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. 결과는 버킷과 요소의 최대 비율입니다.The result is the maximum ratio of elements to buckets.

hcp
IHashCodeProvider IHashCodeProvider IHashCodeProvider IHashCodeProvider

IHashCodeProvider의 모든 키에 해시 코드를 제공하는 Hashtable 개체입니다.The IHashCodeProvider object that supplies the hash codes for all keys in the Hashtable.

또는-or- 각 키의 GetHashCode() 구현인 기본 해시 코드 공급자를 사용하면 null입니다.null to use the default hash code provider, which is each key's implementation of GetHashCode().

comparer
IComparer IComparer IComparer IComparer

두 키가 같은지 여부를 확인하는 데 사용할 IComparer 개체입니다.The IComparer object to use to determine whether two keys are equal.

또는-or- 각 키로 Equals(Object)를 구현한 기본 비교자를 사용하면 null입니다.null to use the default comparer, which is each key's implementation of Equals(Object).

예외

loadFactor가 0.1보다 작습니다.loadFactor is less than 0.1.

또는-or- loadFactor가 1.0보다 큽니다.loadFactor is greater than 1.0.

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
	   
	   // Create the dictionary.
	   SortedList^ mySL = gcnew SortedList;
	   mySL->Add( "FIRST", "Hello" );
	   mySL->Add( "SECOND", "World" );
	   mySL->Add( "THIRD", "!" );
	   
	   // Create a hash table using the default hash code provider and the default comparer.
	   Hashtable^ myHT1 = gcnew Hashtable( mySL, .8f );
	   
	   // Create a hash table using the specified case-insensitive hash code provider and case-insensitive comparer.
	   Hashtable^ myHT2 = gcnew Hashtable( mySL, .8f, gcnew myCultureComparer() );
	   
	   // Create a hash table using the specified KeyComparer.
	   // The KeyComparer uses a case-insensitive hash code provider and a case-insensitive comparer,
	   // which are based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i".
	   CultureInfo^ myCul = gcnew CultureInfo( "tr-TR" );
	   Hashtable^ myHT3 = gcnew Hashtable( mySL, .8f, gcnew myCultureComparer( myCul ) );
	   
	   // Search for a key in each hash table.
	   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) );
	   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) );
	   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) );
	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL, .8f);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(mySL, .8f, 
            new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, .8f, new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL, System.Convert.ToSingle(0.8))

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL, System.Convert.ToSingle(0.8), _
        New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL, System.Convert.ToSingle(0.8), _
        New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

초기 용량을 원본 사전의 요소 수로 설정 됩니다.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. 1.0의 로드 비율을은 적절 한 속도와 크기입니다.A load factor of 1.0 is the best balance between speed and size.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable 개체입니다.The hash code provider dispenses hash codes for keys in the Hashtable object. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

사용자 지정 해시 코드 공급자 및 사용자 지정 비교자를 대/소문자 문자열을 사용 하 여 조회를 수행 하는 등의 시나리오를 사용 하도록 설정 합니다.The custom hash code provider and the custom comparer enable scenarios such as doing lookups with case-insensitive strings.

새 요소의 Hashtable 열거자가 반복는 동일한 순서로 정렬 되는 IDictionary 개체입니다.The elements of the new Hashtable are sorted in the same order in which the enumerator iterates through the IDictionary object.

이 생성자는 (n) 작업, 여기서 n 의 요소 수를 d 매개 변수.This constructor is an O(n) operation, where n is the number of elements in the d parameter.

Hashtable(Int32, Single, IEqualityComparer) Hashtable(Int32, Single, IEqualityComparer) Hashtable(Int32, Single, IEqualityComparer) Hashtable(Int32, Single, IEqualityComparer)

지정된 초기 용량, 로드 비율 및 Hashtable 개체를 사용하여 IEqualityComparer 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, load factor, and IEqualityComparer object.

public:
 Hashtable(int capacity, float loadFactor, System::Collections::IEqualityComparer ^ equalityComparer);
public Hashtable (int capacity, float loadFactor, System.Collections.IEqualityComparer equalityComparer);
new System.Collections.Hashtable : int * single * System.Collections.IEqualityComparer -> System.Collections.Hashtable
Public Sub New (capacity As Integer, loadFactor As Single, equalityComparer As IEqualityComparer)

매개 변수

capacity
Int32 Int32 Int32 Int32

Hashtable 개체가 처음에 포함할 수 있는 대략적인 요소 수입니다.The approximate number of elements that the Hashtable object can initially contain.

loadFactor
Single Single Single Single

최고의 성능을 제공하는 기본값으로 곱한 0.1에서 1.0 사이의 수입니다.A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. 결과는 버킷과 요소의 최대 비율입니다.The result is the maximum ratio of elements to buckets.

equalityComparer
IEqualityComparer IEqualityComparer IEqualityComparer IEqualityComparer

IEqualityComparer과 함께 사용할 해시 코드 공급자와 비교자를 정의하는 Hashtable 개체입니다.The IEqualityComparer object that defines the hash code provider and the comparer to use with the Hashtable.

또는-or- 기본 해시 코드 공급자와 기본 비교자를 사용하면 null입니다.null to use the default hash code provider and the default comparer. 기본 해시 코드 공급자는 각 키의 GetHashCode() 구현이며 기본 비교자는 각 키의 Equals(Object) 구현입니다.The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(Object).

예외

capacity가 0보다 작은 경우capacity is less than zero.

또는-or- loadFactor가 0.1보다 작습니다.loadFactor is less than 0.1.

또는-or- loadFactor가 1.0보다 큽니다.loadFactor is greater than 1.0.

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(3, .8f);
        myHT1->Add("FIRST", "Hello");
        myHT1->Add("SECOND", "World");
        myHT1->Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(3, .8f, gcnew myCultureComparer());
        myHT2->Add("FIRST", "Hello");
        myHT2->Add("SECOND", "World");
        myHT2->Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(3, .8f, gcnew myCultureComparer(myCul));
        myHT3->Add("FIRST", "Hello");
        myHT3->Add("SECOND", "World");
        myHT3->Add("THIRD", "!");

        // Search for a key in each hash table.
		Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));

	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3, .8f);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(3, .8f, new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, .8f, new myCultureComparer(myCul));

        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New Hashtable(3, System.Convert.ToSingle(0.8))
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer that uses
        ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Dim myHT2 As New Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer())

        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based on
        ' the Turkish culture (tr-TR) where "I" is not the uppercase
        ' version of "i".
        Dim myCul As New CultureInfo("tr-TR")
        Dim myHT3 As New Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer(myCul))

        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

    End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

여러 요소를 추가 하는 동안 크기 조정 작업을 수행할 필요가 없습니다 초기 용량을 지정 하는 Hashtable 개체입니다.Specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Hashtable object. 용량을 자동으로 부하 비율에 따라 필요에 따라 증가 합니다.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. 1.0의 로드 비율을은 적절 한 속도와 크기입니다.A load factor of 1.0 is the best balance between speed and size.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

IEqualityComparer 개체 해시 코드 공급자 및 비교자를 모두 포함 됩니다.The IEqualityComparer object includes both the hash code provider and the comparer. 경우는 IEqualityComparer 에 사용 되는 Hashtable 생성자, 개체에서 키로 사용 합니다 Hashtable 재정의할 필요가 없습니다를 Object.GetHashCodeObject.Equals 메서드.If an IEqualityComparer is used in the Hashtable constructor, the objects used as keys in the Hashtable are not required to override the Object.GetHashCode and Object.Equals methods.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

IEqualityComparer 대/소문자 문자열을 사용 하 여 조회를 수행 하는 시나리오도 가능 합니다.The IEqualityComparer enables scenarios such as doing lookups with case-insensitive strings.

이 생성자는 (n) 작업, 여기서 ncapacity 매개 변수입니다.This constructor is an O(n) operation, where n is the capacity parameter.

추가 정보

Hashtable(Int32, IHashCodeProvider, IComparer) Hashtable(Int32, IHashCodeProvider, IComparer) Hashtable(Int32, IHashCodeProvider, IComparer) Hashtable(Int32, IHashCodeProvider, IComparer)

경고

이 API는 현재 사용되지 않습니다.

지정된 초기 용량, 해시 코드 공급자 및 비교자와 기본 로드 비율을 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, hash code provider, comparer, and the default load factor.

public:
 Hashtable(int capacity, System::Collections::IHashCodeProvider ^ hcp, System::Collections::IComparer ^ comparer);
[System.Obsolete("Please use Hashtable(int, IEqualityComparer) instead.")]
public Hashtable (int capacity, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer);
new System.Collections.Hashtable : int * System.Collections.IHashCodeProvider * System.Collections.IComparer -> System.Collections.Hashtable
Public Sub New (capacity As Integer, hcp As IHashCodeProvider, comparer As IComparer)

매개 변수

capacity
Int32 Int32 Int32 Int32

Hashtable 개체가 처음에 포함할 수 있는 대략적인 요소 수입니다.The approximate number of elements that the Hashtable object can initially contain.

hcp
IHashCodeProvider IHashCodeProvider IHashCodeProvider IHashCodeProvider

IHashCodeProvider의 모든 키에 해시 코드를 제공하는 Hashtable 개체입니다.The IHashCodeProvider object that supplies the hash codes for all keys in the Hashtable.

또는-or- 각 키의 GetHashCode() 구현인 기본 해시 코드 공급자를 사용하면 null입니다.null to use the default hash code provider, which is each key's implementation of GetHashCode().

comparer
IComparer IComparer IComparer IComparer

두 키가 같은지 여부를 확인하는 데 사용할 IComparer 개체입니다.The IComparer object to use to determine whether two keys are equal.

또는-or- 각 키로 Equals(Object)를 구현한 기본 비교자를 사용하면 null입니다.null to use the default comparer, which is each key's implementation of Equals(Object).

예외

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(3);
        myHT1->Add("FIRST", "Hello");
        myHT1->Add("SECOND", "World");
        myHT1->Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(3, gcnew myCultureComparer());
        myHT2->Add("FIRST", "Hello");
        myHT2->Add("SECOND", "World");
        myHT2->Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(3, gcnew myCultureComparer(myCul));
        myHT3->Add("FIRST", "Hello");
        myHT3->Add("SECOND", "World");
        myHT3->Add("THIRD", "!");

        // Search for a key in each hash table.
		Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));

	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(3, new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, new myCultureComparer(myCul));
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(3)
      myHT1.Add("FIRST", "Hello")
      myHT1.Add("SECOND", "World")
      myHT1.Add("THIRD", "!")

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(3, New myCultureComparer())
      myHT2.Add("FIRST", "Hello")
      myHT2.Add("SECOND", "World")
      myHT2.Add("THIRD", "!")

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(3, New myCultureComparer(myCul))
      myHT3.Add("FIRST", "Hello")
      myHT3.Add("SECOND", "World")
      myHT3.Add("THIRD", "!")

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

여러 요소를 추가 하는 동안 크기 조정 작업을 수행할 필요가 없습니다 초기 용량을 지정 하는 Hashtable 개체입니다.Specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Hashtable object. 용량을 자동으로 부하 비율에 따라 필요에 따라 증가 합니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

사용자 지정 해시 코드 공급자 및 사용자 지정 비교자를 대/소문자 문자열을 사용 하 여 조회를 수행 하는 등의 시나리오를 사용 하도록 설정 합니다.The custom hash code provider and the custom comparer enable scenarios such as doing lookups with case-insensitive strings.

이 생성자는 (n) 작업, 여기서 ncapacity 매개 변수입니다.This constructor is an O(n) operation, where n is the capacity parameter.

추가 정보

Hashtable(IDictionary, Single, IEqualityComparer) Hashtable(IDictionary, Single, IEqualityComparer) Hashtable(IDictionary, Single, IEqualityComparer) Hashtable(IDictionary, Single, IEqualityComparer)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 지정된 로드 비율 및 IEqualityComparer 개체를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor and IEqualityComparer object.

public:
 Hashtable(System::Collections::IDictionary ^ d, float loadFactor, System::Collections::IEqualityComparer ^ equalityComparer);
public Hashtable (System.Collections.IDictionary d, float loadFactor, System.Collections.IEqualityComparer equalityComparer);
new System.Collections.Hashtable : System.Collections.IDictionary * single * System.Collections.IEqualityComparer -> System.Collections.Hashtable
Public Sub New (d As IDictionary, loadFactor As Single, equalityComparer As IEqualityComparer)

매개 변수

d
IDictionary IDictionary IDictionary IDictionary

IDictionary 개체로 복사할 Hashtable 개체입니다.The IDictionary object to copy to a new Hashtable object.

loadFactor
Single Single Single Single

최고의 성능을 제공하는 기본값으로 곱한 0.1에서 1.0 사이의 수입니다.A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. 결과는 버킷과 요소의 최대 비율입니다.The result is the maximum ratio of elements to buckets.

equalityComparer
IEqualityComparer IEqualityComparer IEqualityComparer IEqualityComparer

IEqualityComparer과 함께 사용할 해시 코드 공급자와 비교자를 정의하는 Hashtable 개체입니다.The IEqualityComparer object that defines the hash code provider and the comparer to use with the Hashtable.

또는-or- 기본 해시 코드 공급자와 기본 비교자를 사용하면 null입니다.null to use the default hash code provider and the default comparer. 기본 해시 코드 공급자는 각 키의 GetHashCode() 구현이며 기본 비교자는 각 키의 Equals(Object) 구현입니다.The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(Object).

예외

loadFactor가 0.1보다 작습니다.loadFactor is less than 0.1.

또는-or- loadFactor가 1.0보다 큽니다.loadFactor is greater than 1.0.

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
	   
	   // Create the dictionary.
	   SortedList^ mySL = gcnew SortedList;
	   mySL->Add( "FIRST", "Hello" );
	   mySL->Add( "SECOND", "World" );
	   mySL->Add( "THIRD", "!" );
	   
	   // Create a hash table using the default hash code provider and the default comparer.
	   Hashtable^ myHT1 = gcnew Hashtable( mySL, .8f );
	   
	   // Create a hash table using the specified case-insensitive hash code provider and case-insensitive comparer.
	   Hashtable^ myHT2 = gcnew Hashtable( mySL, .8f, gcnew myCultureComparer() );
	   
	   // Create a hash table using the specified KeyComparer.
	   // The KeyComparer uses a case-insensitive hash code provider and a case-insensitive comparer,
	   // which are based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i".
	   CultureInfo^ myCul = gcnew CultureInfo( "tr-TR" );
	   Hashtable^ myHT3 = gcnew Hashtable( mySL, .8f, gcnew myCultureComparer( myCul ) );
	   
	   // Search for a key in each hash table.
	   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) );
	   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) );
	   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) );
	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL, .8f);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(mySL, .8f, 
            new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, .8f, new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL, System.Convert.ToSingle(0.8))

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL, System.Convert.ToSingle(0.8), _
        New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL, System.Convert.ToSingle(0.8), _
        New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

초기 용량을 원본 사전의 요소 수로 설정 됩니다.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. 1.0의 로드 비율을은 적절 한 속도와 크기입니다.A load factor of 1.0 is the best balance between speed and size.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

IEqualityComparer 개체 해시 코드 공급자 및 비교자를 모두 포함 됩니다.The IEqualityComparer object includes both the hash code provider and the comparer. 경우는 IEqualityComparer 에 사용 되는 Hashtable 생성자에서 키로 사용 하는 개체를 Hashtable 개체 재정의할 필요가 없습니다를 Object.GetHashCodeObject.Equals 메서드.If an IEqualityComparer is used in the Hashtable constructor, the objects used as keys in the Hashtable object are not required to override the Object.GetHashCode and Object.Equals methods.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

IEqualityComparer 대/소문자 문자열을 사용 하 여 조회를 수행 하는 시나리오도 가능 합니다.The IEqualityComparer enables scenarios such as doing lookups with case-insensitive strings.

새 요소의 Hashtable 열거자가 반복는 동일한 순서로 정렬 되는 IDictionary 개체입니다.The elements of the new Hashtable are sorted in the same order in which the enumerator iterates through the IDictionary object.

이 생성자는 (n) 작업, 여기서 n 의 요소 수를 d 매개 변수.This constructor is an O(n) operation, where n is the number of elements in the d parameter.

추가 정보

Hashtable(IDictionary, IHashCodeProvider, IComparer) Hashtable(IDictionary, IHashCodeProvider, IComparer) Hashtable(IDictionary, IHashCodeProvider, IComparer) Hashtable(IDictionary, IHashCodeProvider, IComparer)

경고

이 API는 현재 사용되지 않습니다.

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 기본 로드 비율과 지정된 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor, and the specified hash code provider and comparer. 이 API는 사용되지 않습니다.This API is obsolete. 다른 방법을 보려면 Hashtable(IDictionary, IEqualityComparer)를 참조하십시오.For an alternative, see Hashtable(IDictionary, IEqualityComparer).

public:
 Hashtable(System::Collections::IDictionary ^ d, System::Collections::IHashCodeProvider ^ hcp, System::Collections::IComparer ^ comparer);
[System.Obsolete("Please use Hashtable(IDictionary, IEqualityComparer) instead.")]
public Hashtable (System.Collections.IDictionary d, System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer);
new System.Collections.Hashtable : System.Collections.IDictionary * System.Collections.IHashCodeProvider * System.Collections.IComparer -> System.Collections.Hashtable
Public Sub New (d As IDictionary, hcp As IHashCodeProvider, comparer As IComparer)

매개 변수

d
IDictionary IDictionary IDictionary IDictionary

IDictionary 개체로 복사할 Hashtable 개체입니다.The IDictionary object to copy to a new Hashtable object.

hcp
IHashCodeProvider IHashCodeProvider IHashCodeProvider IHashCodeProvider

IHashCodeProvider의 모든 키에 해시 코드를 제공하는 Hashtable 개체입니다.The IHashCodeProvider object that supplies the hash codes for all keys in the Hashtable.

또는-or- 각 키의 GetHashCode() 구현인 기본 해시 코드 공급자를 사용하면 null입니다.null to use the default hash code provider, which is each key's implementation of GetHashCode().

comparer
IComparer IComparer IComparer IComparer

두 키가 같은지 여부를 확인하는 데 사용할 IComparer 개체입니다.The IComparer object to use to determine whether two keys are equal.

또는-or- 각 키로 Equals(Object)를 구현한 기본 비교자를 사용하면 null입니다.null to use the default comparer, which is each key's implementation of Equals(Object).

예외

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
    static void Main()
    {
        // Create the dictionary.
        SortedList^ mySL = gcnew SortedList();
        mySL->Add("FIRST", "Hello");
        mySL->Add("SECOND", "World");
        mySL->Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(mySL, gcnew myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(mySL, gcnew myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));
    }
};

int main()
{
    SamplesHashtable::Main();
};

/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(mySL, new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL)

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL, New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL, New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

초기 용량을 원본 사전의 요소 수로 설정 됩니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable 개체입니다.The hash code provider dispenses hash codes for keys in the Hashtable object. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

사용자 지정 해시 코드 공급자 및 사용자 지정 비교자를 대/소문자 문자열을 사용 하 여 조회를 수행 하는 등의 시나리오를 사용 하도록 설정 합니다.The custom hash code provider and the custom comparer enable scenarios such as doing lookups with case-insensitive strings.

새 요소의 Hashtable 열거자가 반복는 동일한 순서로 정렬 되는 IDictionary 개체입니다.The elements of the new Hashtable are sorted in the same order in which the enumerator iterates through the IDictionary object.

이 생성자는 (n) 작업, 여기서 n 의 요소 수를 d 매개 변수.This constructor is an O(n) operation, where n is the number of elements in the d parameter.

추가 정보

Hashtable(Int32, Single) Hashtable(Int32, Single) Hashtable(Int32, Single) Hashtable(Int32, Single)

지정된 초기 용량 및 로드 비율과 기본 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity and load factor, and the default hash code provider and comparer.

public:
 Hashtable(int capacity, float loadFactor);
public Hashtable (int capacity, float loadFactor);
new System.Collections.Hashtable : int * single -> System.Collections.Hashtable
Public Sub New (capacity As Integer, loadFactor As Single)

매개 변수

capacity
Int32 Int32 Int32 Int32

Hashtable 개체가 처음에 포함할 수 있는 대략적인 요소 수입니다.The approximate number of elements that the Hashtable object can initially contain.

loadFactor
Single Single Single Single

최고의 성능을 제공하는 기본값으로 곱한 0.1에서 1.0 사이의 수입니다.A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. 결과는 버킷과 요소의 최대 비율입니다.The result is the maximum ratio of elements to buckets.

예외

capacity가 0보다 작은 경우capacity is less than zero.

또는-or- loadFactor가 0.1보다 작습니다.loadFactor is less than 0.1.

또는-or- loadFactor가 1.0보다 큽니다.loadFactor is greater than 1.0.

capacity가 오버플로를 일으킬 수 있습니다.capacity is causing an overflow.

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(3, .8f);
        myHT1->Add("FIRST", "Hello");
        myHT1->Add("SECOND", "World");
        myHT1->Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(3, .8f, gcnew myCultureComparer());
        myHT2->Add("FIRST", "Hello");
        myHT2->Add("SECOND", "World");
        myHT2->Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(3, .8f, gcnew myCultureComparer(myCul));
        myHT3->Add("FIRST", "Hello");
        myHT3->Add("SECOND", "World");
        myHT3->Add("THIRD", "!");

        // Search for a key in each hash table.
		Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));

	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3, .8f);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(3, .8f, new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, .8f, new myCultureComparer(myCul));

        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New Hashtable(3, System.Convert.ToSingle(0.8))
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer that uses
        ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Dim myHT2 As New Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer())

        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based on
        ' the Turkish culture (tr-TR) where "I" is not the uppercase
        ' version of "i".
        Dim myCul As New CultureInfo("tr-TR")
        Dim myHT3 As New Hashtable(3, System.Convert.ToSingle(0.8), _
            New myCultureComparer(myCul))

        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

    End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

여러 요소를 추가 하는 동안 크기 조정 작업을 수행할 필요가 없습니다 초기 용량을 지정 하는 Hashtable 개체입니다.Specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Hashtable object. 용량을 자동으로 부하 비율에 따라 필요에 따라 증가 합니다.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. 1.0의 로드 비율을은 적절 한 속도와 크기입니다.A load factor of 1.0 is the best balance between speed and size.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

이 생성자는 (n) 작업, 여기서 ncapacity 매개 변수입니다.This constructor is an O(n) operation, where n is the capacity parameter.

추가 정보

Hashtable(SerializationInfo, StreamingContext) Hashtable(SerializationInfo, StreamingContext) Hashtable(SerializationInfo, StreamingContext) Hashtable(SerializationInfo, StreamingContext)

지정된 HashtableSerializationInfo 개체를 사용하여 serialize할 수 있는 StreamingContext 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class that is serializable using the specified SerializationInfo and StreamingContext objects.

protected:
 Hashtable(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected Hashtable (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Collections.Hashtable : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Hashtable
Protected Sub New (info As SerializationInfo, context As StreamingContext)

매개 변수

info
SerializationInfo SerializationInfo SerializationInfo SerializationInfo

SerializationInfo 개체를 serialize하는 데 필요한 정보가 들어 있는 Hashtable 개체입니다.A SerializationInfo object containing the information required to serialize the Hashtable object.

context
StreamingContext StreamingContext StreamingContext StreamingContext

StreamingContext와 관련하여 serialize된 스트림의 소스와 대상이 포함된 Hashtable개체입니다.A StreamingContext object containing the source and destination of the serialized stream associated with the Hashtable.

예외

설명

해시 테이블의 용량 최적의 부하 비율에 따라 해시 테이블 버킷 수를 계산 하는 데 사용 됩니다.A hash table's capacity is used to calculate the optimal number of hash table buckets based on the load factor. 용량 자동으로 증가 해야 하는 경우.Capacity is automatically increased as required.

로드 비율에 버킷과 요소의 최대 비율입니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable 개체입니다.The hash code provider dispenses hash codes for keys in the Hashtable object. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

이 생성자는 O (n) 작업, 여기서 nCount합니다.This constructor is an O(n) operation, where n is Count.

직렬화 및 역직렬화에 대 한 열거자 때문에 Hashtable 요소를 다시 정렬 될 하면, 호출 하지 않고 열거를 계속 불가능는 Reset 메서드.Because serializing and deserializing an enumerator for a Hashtable can cause the elements to become reordered, it is not possible to continue enumeration without calling the Reset method.

추가 정보

Hashtable(IHashCodeProvider, IComparer) Hashtable(IHashCodeProvider, IComparer) Hashtable(IHashCodeProvider, IComparer) Hashtable(IHashCodeProvider, IComparer)

경고

이 API는 현재 사용되지 않습니다.

기본 초기 용량 및 로드 비율과 지정된 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor, and the specified hash code provider and comparer.

public:
 Hashtable(System::Collections::IHashCodeProvider ^ hcp, System::Collections::IComparer ^ comparer);
[System.Obsolete("Please use Hashtable(IEqualityComparer) instead.")]
public Hashtable (System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer);
new System.Collections.Hashtable : System.Collections.IHashCodeProvider * System.Collections.IComparer -> System.Collections.Hashtable
Public Sub New (hcp As IHashCodeProvider, comparer As IComparer)

매개 변수

hcp
IHashCodeProvider IHashCodeProvider IHashCodeProvider IHashCodeProvider

IHashCodeProvider 개체의 모든 키에 대한 해시 코드를 제공하는 Hashtable 개체입니다.The IHashCodeProvider object that supplies the hash codes for all keys in the Hashtable object.

또는-or- 각 키의 GetHashCode() 구현인 기본 해시 코드 공급자를 사용하면 null입니다.null to use the default hash code provider, which is each key's implementation of GetHashCode().

comparer
IComparer IComparer IComparer IComparer

두 키가 같은지 여부를 확인하는 데 사용할 IComparer 개체입니다.The IComparer object to use to determine whether two keys are equal.

또는-or- 각 키로 Equals(Object)를 구현한 기본 비교자를 사용하면 null입니다.null to use the default comparer, which is each key's implementation of Equals(Object).

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myComparer : IEqualityComparer
{
public:
    virtual bool Equals(Object^ x, Object^ y) 
    {
        return x->Equals(y);
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

ref class myCultureComparer : IEqualityComparer
{
private:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

    virtual bool Equals(Object^ x, Object^ y) 
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

int main()
{
   
   // Create a hash table using the default hash code provider and the default comparer.
   Hashtable^ myHT1 = gcnew Hashtable((IEqualityComparer^)nullptr);
   myHT1->Add( "FIRST", "Hello" );
   myHT1->Add( "SECOND", "World" );
   myHT1->Add( "THIRD", "!" );
   
   // Create a hash table using the specified IEqualityComparer that uses
   // the default Object.Equals to determine equality.
   Hashtable^ myHT2 = gcnew Hashtable(gcnew myComparer());
   myHT2->Add( "FIRST", "Hello" );
   myHT2->Add( "SECOND", "World" );
   myHT2->Add( "THIRD", "!" );
   
   // Create a hash table using a case-insensitive hash code provider and
   // case-insensitive comparer based on the InvariantCulture.
   Hashtable^ myHT3 = gcnew Hashtable(
            CaseInsensitiveHashCodeProvider::DefaultInvariant,
            CaseInsensitiveComparer::DefaultInvariant);
   myHT3->Add( "FIRST", "Hello" );
   myHT3->Add( "SECOND", "World" );
   myHT3->Add( "THIRD", "!" );
   
   // Create a hash table using an IEqualityComparer that is based on
   // the Turkish culture (tr-TR) where "I" is not the uppercase
   // version of "i".
   CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
   Hashtable^ myHT4 = gcnew Hashtable( gcnew myCultureComparer(myCul) );
   myHT4->Add( "FIRST", "Hello" );
   myHT4->Add( "SECOND", "World" );
   myHT4->Add( "THIRD", "!" );
   
   // Search for a key in each hash table.
   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey( "first" ) );
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/
using System;
using System.Collections;
using System.Globalization;

class myComparer : IEqualityComparer
{
    public new bool Equals(object x, object y)
    {
        return x.Equals(y);
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable();
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the default Object.Equals to determine equality.
        Hashtable myHT2 = new Hashtable(new myComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using a case-insensitive hash code provider and
        // case-insensitive comparer based on the InvariantCulture.
        Hashtable myHT3 = new Hashtable(
            CaseInsensitiveHashCodeProvider.DefaultInvariant,
            CaseInsensitiveComparer.DefaultInvariant);
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT4 = new Hashtable(new myCultureComparer(myCul));
        myHT4.Add("FIRST", "Hello");
        myHT4.Add("SECOND", "World");
        myHT4.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));
        Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myComparer
    Implements IEqualityComparer
    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        Return x.Equals(y)
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode

        Return obj.ToString().ToLower().GetHashCode()
    End Function

End Class

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New Hashtable()
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer that uses
        ' the default Object.Equals to determine equality.
        Dim myHT2 As New Hashtable(New myComparer())
        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using a case-insensitive hash code provider and
        ' case-insensitive comparer based on the InvariantCulture.
        Dim myHT3 As New Hashtable( _
            CaseInsensitiveHashCodeProvider.DefaultInvariant, _
            CaseInsensitiveComparer.DefaultInvariant)
        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based on
        ' the Turkish culture (tr-TR) where "I" is not the uppercase
        ' version of "i".
        Dim myCul As New CultureInfo("tr-TR")
        Dim myHT4 As New Hashtable(New myCultureComparer(myCul))
        myHT4.Add("FIRST", "Hello")
        myHT4.Add("SECOND", "World")
        myHT4.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))
        Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first"))

    End Sub

End Class

'This code produces the following output.
'Results vary depending on the system's culture settings.

'first is in myHT1: False
'first is in myHT2: False
'first is in myHT3: True
'first is in myHT4: False

설명

해시 테이블의 용량 최적의 부하 비율에 따라 해시 테이블 버킷 수를 계산 하는 데 사용 됩니다.A hash table's capacity is used to calculate the optimal number of hash table buckets based on the load factor. 용량 자동으로 증가 해야 하는 경우.Capacity is automatically increased as required.

로드 비율에 버킷과 요소의 최대 비율입니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable 개체입니다.The hash code provider dispenses hash codes for keys in the Hashtable object. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

사용자 지정 해시 코드 공급자 및 사용자 지정 비교자를 대/소문자 문자열을 사용 하 여 조회를 수행 하는 등의 시나리오를 사용 하도록 설정 합니다.The custom hash code provider and the custom comparer enable scenarios such as doing lookups with case-insensitive strings.

이 생성자는 o (1) 작업입니다.This constructor is an O(1) operation.

추가 정보

Hashtable(IDictionary, Single) Hashtable(IDictionary, Single) Hashtable(IDictionary, Single) Hashtable(IDictionary, Single)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 지정된 로드 비율과 기본 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor, and the default hash code provider and comparer.

public:
 Hashtable(System::Collections::IDictionary ^ d, float loadFactor);
public Hashtable (System.Collections.IDictionary d, float loadFactor);
new System.Collections.Hashtable : System.Collections.IDictionary * single -> System.Collections.Hashtable
Public Sub New (d As IDictionary, loadFactor As Single)

매개 변수

d
IDictionary IDictionary IDictionary IDictionary

IDictionary 개체로 복사할 Hashtable 개체입니다.The IDictionary object to copy to a new Hashtable object.

loadFactor
Single Single Single Single

최고의 성능을 제공하는 기본값으로 곱한 0.1에서 1.0 사이의 수입니다.A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. 결과는 버킷과 요소의 최대 비율입니다.The result is the maximum ratio of elements to buckets.

예외

loadFactor가 0.1보다 작습니다.loadFactor is less than 0.1.

또는-or- loadFactor가 1.0보다 큽니다.loadFactor is greater than 1.0.

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
	   
	   // Create the dictionary.
	   SortedList^ mySL = gcnew SortedList;
	   mySL->Add( "FIRST", "Hello" );
	   mySL->Add( "SECOND", "World" );
	   mySL->Add( "THIRD", "!" );
	   
	   // Create a hash table using the default hash code provider and the default comparer.
	   Hashtable^ myHT1 = gcnew Hashtable( mySL, .8f );
	   
	   // Create a hash table using the specified case-insensitive hash code provider and case-insensitive comparer.
	   Hashtable^ myHT2 = gcnew Hashtable( mySL, .8f, gcnew myCultureComparer() );
	   
	   // Create a hash table using the specified KeyComparer.
	   // The KeyComparer uses a case-insensitive hash code provider and a case-insensitive comparer,
	   // which are based on the Turkish culture (tr-TR), where "I" is not the uppercase version of "i".
	   CultureInfo^ myCul = gcnew CultureInfo( "tr-TR" );
	   Hashtable^ myHT3 = gcnew Hashtable( mySL, .8f, gcnew myCultureComparer( myCul ) );
	   
	   // Search for a key in each hash table.
	   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) );
	   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) );
	   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) );
	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL, .8f);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(mySL, .8f, 
            new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, .8f, new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL, System.Convert.ToSingle(0.8))

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL, System.Convert.ToSingle(0.8), _
        New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL, System.Convert.ToSingle(0.8), _
        New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

초기 용량을 원본 사전의 요소 수로 설정 됩니다.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. 1.0의 로드 비율을은 적절 한 속도와 크기입니다.A load factor of 1.0 is the best balance between speed and size.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable 개체입니다.The hash code provider dispenses hash codes for keys in the Hashtable object. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

새 요소의 Hashtable 열거자가 반복는 동일한 순서로 정렬 되는 IDictionary 개체입니다.The elements of the new Hashtable are sorted in the same order in which the enumerator iterates through the IDictionary object.

이 생성자는 (n) 작업, 여기서 n 의 요소 수를 d 매개 변수.This constructor is an O(n) operation, where n is the number of elements in the d parameter.

추가 정보

Hashtable(IDictionary, IEqualityComparer) Hashtable(IDictionary, IEqualityComparer) Hashtable(IDictionary, IEqualityComparer) Hashtable(IDictionary, IEqualityComparer)

지정된 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to a new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 기본 로드 비율과 지정된 IEqualityComparer 개체를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor and the specified IEqualityComparer object.

public:
 Hashtable(System::Collections::IDictionary ^ d, System::Collections::IEqualityComparer ^ equalityComparer);
public Hashtable (System.Collections.IDictionary d, System.Collections.IEqualityComparer equalityComparer);
new System.Collections.Hashtable : System.Collections.IDictionary * System.Collections.IEqualityComparer -> System.Collections.Hashtable
Public Sub New (d As IDictionary, equalityComparer As IEqualityComparer)

매개 변수

d
IDictionary IDictionary IDictionary IDictionary

IDictionary 개체로 복사할 Hashtable 개체입니다.The IDictionary object to copy to a new Hashtable object.

equalityComparer
IEqualityComparer IEqualityComparer IEqualityComparer IEqualityComparer

IEqualityComparer과 함께 사용할 해시 코드 공급자와 비교자를 정의하는 Hashtable 개체입니다.The IEqualityComparer object that defines the hash code provider and the comparer to use with the Hashtable.

또는-or- 기본 해시 코드 공급자와 기본 비교자를 사용하면 null입니다.null to use the default hash code provider and the default comparer. 기본 해시 코드 공급자는 각 키의 GetHashCode() 구현이며 기본 비교자는 각 키의 Equals(Object) 구현입니다.The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(Object).

예외

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
    static void Main()
    {
        // Create the dictionary.
        SortedList^ mySL = gcnew SortedList();
        mySL->Add("FIRST", "Hello");
        mySL->Add("SECOND", "World");
        mySL->Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(mySL, gcnew myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(mySL, gcnew myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));
    }
};

int main()
{
    SamplesHashtable::Main();
};

/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(mySL, new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL)

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL, New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL, New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

초기 용량을 원본 사전의 요소 수로 설정 됩니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

IEqualityComparer 개체 해시 코드 공급자 및 비교자를 모두 포함 됩니다.The IEqualityComparer object includes both the hash code provider and the comparer. 경우는 IEqualityComparer 에 사용 되는 Hashtable 생성자에서 키로 사용 하는 개체를 Hashtable 개체 재정의할 필요가 없습니다를 Object.GetHashCodeObject.Equals 메서드.If an IEqualityComparer is used in the Hashtable constructor, the objects used as keys in the Hashtable object are not required to override the Object.GetHashCode and Object.Equals methods.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

IEqualityComparer 대/소문자 문자열을 사용 하 여 조회를 수행 하는 시나리오도 가능 합니다.The IEqualityComparer enables scenarios such as doing lookups with case-insensitive strings.

새 요소의 Hashtable 열거자가 반복는 동일한 순서로 정렬 되는 IDictionary 개체입니다.The elements of the new Hashtable are sorted in the same order in which the enumerator iterates through the IDictionary object.

이 생성자는 (n) 작업, 여기서 n 의 요소 수를 d 매개 변수.This constructor is an O(n) operation, where n is the number of elements in the d parameter.

추가 정보

Hashtable(Int32) Hashtable(Int32) Hashtable(Int32) Hashtable(Int32)

지정된 초기 용량과 기본 로드 비율, 해시 코드 공급자 및 비교자를 사용하여 Hashtable 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity, and the default load factor, hash code provider, and comparer.

public:
 Hashtable(int capacity);
public Hashtable (int capacity);
new System.Collections.Hashtable : int -> System.Collections.Hashtable
Public Sub New (capacity As Integer)

매개 변수

capacity
Int32 Int32 Int32 Int32

Hashtable 개체가 처음에 포함할 수 있는 대략적인 요소 수입니다.The approximate number of elements that the Hashtable object can initially contain.

예외

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(3);
        myHT1->Add("FIRST", "Hello");
        myHT1->Add("SECOND", "World");
        myHT1->Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(3, gcnew myCultureComparer());
        myHT2->Add("FIRST", "Hello");
        myHT2->Add("SECOND", "World");
        myHT2->Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(3, gcnew myCultureComparer(myCul));
        myHT3->Add("FIRST", "Hello");
        myHT3->Add("SECOND", "World");
        myHT3->Add("THIRD", "!");

        // Search for a key in each hash table.
		Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));

	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(3, new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, new myCultureComparer(myCul));
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(3)
      myHT1.Add("FIRST", "Hello")
      myHT1.Add("SECOND", "World")
      myHT1.Add("THIRD", "!")

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(3, New myCultureComparer())
      myHT2.Add("FIRST", "Hello")
      myHT2.Add("SECOND", "World")
      myHT2.Add("THIRD", "!")

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(3, New myCultureComparer(myCul))
      myHT3.Add("FIRST", "Hello")
      myHT3.Add("SECOND", "World")
      myHT3.Add("THIRD", "!")

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

여러 요소를 추가 하는 동안 크기 조정 작업을 수행할 필요가 없습니다 초기 용량을 지정 하는 Hashtable 개체입니다.Specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Hashtable object. 용량을 자동으로 부하 비율에 따라 필요에 따라 증가 합니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

이 생성자는 O (n) 작업, 여기서 ncapacity합니다.This constructor is an O(n) operation, where n is capacity.

추가 정보

Hashtable(IEqualityComparer) Hashtable(IEqualityComparer) Hashtable(IEqualityComparer) Hashtable(IEqualityComparer)

기본 초기 용량 및 로드 비율과 지정된 Hashtable 개체를 사용하여 IEqualityComparer 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the default initial capacity and load factor, and the specified IEqualityComparer object.

public:
 Hashtable(System::Collections::IEqualityComparer ^ equalityComparer);
public Hashtable (System.Collections.IEqualityComparer equalityComparer);
new System.Collections.Hashtable : System.Collections.IEqualityComparer -> System.Collections.Hashtable
Public Sub New (equalityComparer As IEqualityComparer)

매개 변수

equalityComparer
IEqualityComparer IEqualityComparer IEqualityComparer IEqualityComparer

IEqualityComparer 개체와 함께 사용할 해시 코드 공급자와 비교자를 정의하는 Hashtable 개체입니다.The IEqualityComparer object that defines the hash code provider and the comparer to use with the Hashtable object.

또는-or- 기본 해시 코드 공급자와 기본 비교자를 사용하면 null입니다.null to use the default hash code provider and the default comparer. 기본 해시 코드 공급자는 각 키의 GetHashCode() 구현이며 기본 비교자는 각 키의 Equals(Object) 구현입니다.The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(Object).

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myComparer : IEqualityComparer
{
public:
    virtual bool Equals(Object^ x, Object^ y) 
    {
        return x->Equals(y);
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

ref class myCultureComparer : IEqualityComparer
{
private:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

    virtual bool Equals(Object^ x, Object^ y) 
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    virtual int GetHashCode(Object^ obj)
    {
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

int main()
{
   
   // Create a hash table using the default hash code provider and the default comparer.
   Hashtable^ myHT1 = gcnew Hashtable((IEqualityComparer^)nullptr);
   myHT1->Add( "FIRST", "Hello" );
   myHT1->Add( "SECOND", "World" );
   myHT1->Add( "THIRD", "!" );
   
   // Create a hash table using the specified IEqualityComparer that uses
   // the default Object.Equals to determine equality.
   Hashtable^ myHT2 = gcnew Hashtable(gcnew myComparer());
   myHT2->Add( "FIRST", "Hello" );
   myHT2->Add( "SECOND", "World" );
   myHT2->Add( "THIRD", "!" );
   
   // Create a hash table using a case-insensitive hash code provider and
   // case-insensitive comparer based on the InvariantCulture.
   Hashtable^ myHT3 = gcnew Hashtable(
            CaseInsensitiveHashCodeProvider::DefaultInvariant,
            CaseInsensitiveComparer::DefaultInvariant);
   myHT3->Add( "FIRST", "Hello" );
   myHT3->Add( "SECOND", "World" );
   myHT3->Add( "THIRD", "!" );
   
   // Create a hash table using an IEqualityComparer that is based on
   // the Turkish culture (tr-TR) where "I" is not the uppercase
   // version of "i".
   CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
   Hashtable^ myHT4 = gcnew Hashtable( gcnew myCultureComparer(myCul) );
   myHT4->Add( "FIRST", "Hello" );
   myHT4->Add( "SECOND", "World" );
   myHT4->Add( "THIRD", "!" );
   
   // Search for a key in each hash table.
   Console::WriteLine( "first is in myHT1: {0}", myHT1->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT2: {0}", myHT2->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT3: {0}", myHT3->ContainsKey( "first" ) );
   Console::WriteLine( "first is in myHT4: {0}", myHT4->ContainsKey( "first" ) );
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/
using System;
using System.Collections;
using System.Globalization;

class myComparer : IEqualityComparer
{
    public new bool Equals(object x, object y)
    {
        return x.Equals(y);
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable();
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the default Object.Equals to determine equality.
        Hashtable myHT2 = new Hashtable(new myComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using a case-insensitive hash code provider and
        // case-insensitive comparer based on the InvariantCulture.
        Hashtable myHT3 = new Hashtable(
            CaseInsensitiveHashCodeProvider.DefaultInvariant,
            CaseInsensitiveComparer.DefaultInvariant);
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT4 = new Hashtable(new myCultureComparer(myCul));
        myHT4.Add("FIRST", "Hello");
        myHT4.Add("SECOND", "World");
        myHT4.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));
        Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: False
first is in myHT3: True
first is in myHT4: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myComparer
    Implements IEqualityComparer
    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        Return x.Equals(y)
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode

        Return obj.ToString().ToLower().GetHashCode()
    End Function

End Class

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable

    Public Shared Sub Main()

        ' Create a hash table using the default comparer.
        Dim myHT1 As New Hashtable()
        myHT1.Add("FIRST", "Hello")
        myHT1.Add("SECOND", "World")
        myHT1.Add("THIRD", "!")

        ' Create a hash table using the specified IEqualityComparer that uses
        ' the default Object.Equals to determine equality.
        Dim myHT2 As New Hashtable(New myComparer())
        myHT2.Add("FIRST", "Hello")
        myHT2.Add("SECOND", "World")
        myHT2.Add("THIRD", "!")

        ' Create a hash table using a case-insensitive hash code provider and
        ' case-insensitive comparer based on the InvariantCulture.
        Dim myHT3 As New Hashtable( _
            CaseInsensitiveHashCodeProvider.DefaultInvariant, _
            CaseInsensitiveComparer.DefaultInvariant)
        myHT3.Add("FIRST", "Hello")
        myHT3.Add("SECOND", "World")
        myHT3.Add("THIRD", "!")

        ' Create a hash table using an IEqualityComparer that is based on
        ' the Turkish culture (tr-TR) where "I" is not the uppercase
        ' version of "i".
        Dim myCul As New CultureInfo("tr-TR")
        Dim myHT4 As New Hashtable(New myCultureComparer(myCul))
        myHT4.Add("FIRST", "Hello")
        myHT4.Add("SECOND", "World")
        myHT4.Add("THIRD", "!")

        ' Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))
        Console.WriteLine("first is in myHT4: {0}", myHT4.ContainsKey("first"))

    End Sub

End Class

'This code produces the following output.
'Results vary depending on the system's culture settings.

'first is in myHT1: False
'first is in myHT2: False
'first is in myHT3: True
'first is in myHT4: False

설명

해시 테이블의 용량 최적의 부하 비율에 따라 해시 테이블 버킷 수를 계산 하는 데 사용 됩니다.A hash table's capacity is used to calculate the optimal number of hash table buckets based on the load factor. 용량 자동으로 증가 해야 하는 경우.Capacity is automatically increased as required.

로드 비율에 버킷과 요소의 최대 비율입니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

IEqualityComparer 개체 해시 코드 공급자 및 비교자를 모두 포함 됩니다.The IEqualityComparer object includes both the hash code provider and the comparer. 경우는 IEqualityComparer 에 사용 되는 Hashtable 생성자에서 키로 사용 하는 개체를 Hashtable 개체 재정의할 필요가 없습니다를 Object.GetHashCodeObject.Equals 메서드.If an IEqualityComparer is used in the Hashtable constructor, the objects used as keys in the Hashtable object are not required to override the Object.GetHashCode and Object.Equals methods.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

IEqualityComparer 대/소문자 문자열을 사용 하 여 조회를 수행 하는 시나리오도 가능 합니다.The IEqualityComparer enables scenarios such as doing lookups with case-insensitive strings.

이 생성자는 o (1) 작업입니다.This constructor is an O(1) operation.

추가 정보

Hashtable(IDictionary) Hashtable(IDictionary) Hashtable(IDictionary) Hashtable(IDictionary)

지정한 사전의 요소를 새 Hashtable 개체에 복사하여 Hashtable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. Hashtable 개체는 복사된 요소 수와 같은 초기 용량을 갖고 있고 기본 로드 비율, 해시 코드 공급자 및 비교자를 사용합니다.The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the default load factor, hash code provider, and comparer.

public:
 Hashtable(System::Collections::IDictionary ^ d);
public Hashtable (System.Collections.IDictionary d);
new System.Collections.Hashtable : System.Collections.IDictionary -> System.Collections.Hashtable
Public Sub New (d As IDictionary)

매개 변수

d
IDictionary IDictionary IDictionary IDictionary

IDictionary 개체로 복사할 Hashtable 개체입니다.The IDictionary object to copy to a new Hashtable object.

예외

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
    static void Main()
    {
        // Create the dictionary.
        SortedList^ mySL = gcnew SortedList();
        mySL->Add("FIRST", "Hello");
        mySL->Add("SECOND", "World");
        mySL->Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(mySL, gcnew myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(mySL, gcnew myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));
    }
};

int main()
{
    SamplesHashtable::Main();
};

/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create the dictionary.
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(mySL);

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(mySL, new myCultureComparer());

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(mySL, new myCultureComparer(myCul));

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output. 
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create the dictionary.
      Dim mySL As New SortedList()
      mySL.Add("FIRST", "Hello")
      mySL.Add("SECOND", "World")
      mySL.Add("THIRD", "!")

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(mySL)

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(mySL, New myCultureComparer())

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(mySL, New myCultureComparer(myCul))

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

초기 용량을 원본 사전의 요소 수로 설정 됩니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable 개체입니다.The hash code provider dispenses hash codes for keys in the Hashtable object. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

새 요소의 Hashtable 열거자가 반복는 동일한 순서로 정렬 되는 IDictionary 개체입니다.The elements of the new Hashtable are sorted in the same order in which the enumerator iterates through the IDictionary object.

이 생성자는 (n) 작업, 여기서 n 의 요소 수를 d 매개 변수.This constructor is an O(n) operation, where n is the number of elements in the d parameter.

추가 정보

Hashtable(Int32, IEqualityComparer) Hashtable(Int32, IEqualityComparer) Hashtable(Int32, IEqualityComparer) Hashtable(Int32, IEqualityComparer)

지정된 초기 용량 및 Hashtable와 기본 로드 비율을 사용하여 IEqualityComparer 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes a new, empty instance of the Hashtable class using the specified initial capacity and IEqualityComparer, and the default load factor.

public:
 Hashtable(int capacity, System::Collections::IEqualityComparer ^ equalityComparer);
public Hashtable (int capacity, System.Collections.IEqualityComparer equalityComparer);
new System.Collections.Hashtable : int * System.Collections.IEqualityComparer -> System.Collections.Hashtable
Public Sub New (capacity As Integer, equalityComparer As IEqualityComparer)

매개 변수

capacity
Int32 Int32 Int32 Int32

Hashtable 개체가 처음에 포함할 수 있는 대략적인 요소 수입니다.The approximate number of elements that the Hashtable object can initially contain.

equalityComparer
IEqualityComparer IEqualityComparer IEqualityComparer IEqualityComparer

IEqualityComparer과 함께 사용할 해시 코드 공급자와 비교자를 정의하는 Hashtable 개체입니다.The IEqualityComparer object that defines the hash code provider and the comparer to use with the Hashtable.

또는-or- 기본 해시 코드 공급자와 기본 비교자를 사용하면 null입니다.null to use the default hash code provider and the default comparer. 기본 해시 코드 공급자는 각 키의 GetHashCode() 구현이며 기본 비교자는 각 키의 Equals(Object) 구현입니다.The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(Object).

예외

예제

다음 코드 예제를 사용 하 여 해시 테이블을 다른 만듭니다 Hashtable 생성자 각각 같은 요소를 포함 하는 경우에 해시 테이블의 동작의 차이 보여 줍니다.The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.

using namespace System;
using namespace System::Collections;
using namespace System::Globalization;

ref class myCultureComparer : public IEqualityComparer
{
public:
    CaseInsensitiveComparer^ myComparer;

public:
    myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer::DefaultInvariant;
    }

public:
    myCultureComparer(CultureInfo^ myCulture)
    {
        myComparer = gcnew CaseInsensitiveComparer(myCulture);
    }

public:
    virtual bool Equals(Object^ x, Object^ y)
    {
        if (myComparer->Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

public:
    virtual int GetHashCode(Object^ obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj->ToString()->ToLower()->GetHashCode();
    }
};

public ref class SamplesHashtable
{

public:
	static void Main()
	{
        // Create a hash table using the default comparer.
        Hashtable^ myHT1 = gcnew Hashtable(3);
        myHT1->Add("FIRST", "Hello");
        myHT1->Add("SECOND", "World");
        myHT1->Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable^ myHT2 = gcnew Hashtable(3, gcnew myCultureComparer());
        myHT2->Add("FIRST", "Hello");
        myHT2->Add("SECOND", "World");
        myHT2->Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo^ myCul = gcnew CultureInfo("tr-TR");
        Hashtable^ myHT3 = gcnew Hashtable(3, gcnew myCultureComparer(myCul));
        myHT3->Add("FIRST", "Hello");
        myHT3->Add("SECOND", "World");
        myHT3->Add("THIRD", "!");

        // Search for a key in each hash table.
		Console::WriteLine("first is in myHT1: {0}", myHT1->ContainsKey("first"));
        Console::WriteLine("first is in myHT2: {0}", myHT2->ContainsKey("first"));
        Console::WriteLine("first is in myHT3: {0}", myHT3->ContainsKey("first"));

	}
};

int main()
{
	SamplesHashtable::Main();
}

/* 
This code produces the following output.  Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/
using System;
using System.Collections;
using System.Globalization;

class myCultureComparer : IEqualityComparer
{
    public CaseInsensitiveComparer myComparer;

    public myCultureComparer()
    {
        myComparer = CaseInsensitiveComparer.DefaultInvariant;
    }

    public myCultureComparer(CultureInfo myCulture)
    {
        myComparer = new CaseInsensitiveComparer(myCulture);
    }

    public new bool Equals(object x, object y)
    {
        if (myComparer.Compare(x, y) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int GetHashCode(object obj)
    {
        // Compare the hash code for the lowercase versions of the strings.
        return obj.ToString().ToLower().GetHashCode();
    }
}

public class SamplesHashtable
{

    public static void Main()
    {

        // Create a hash table using the default comparer.
        Hashtable myHT1 = new Hashtable(3);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        // Create a hash table using the specified IEqualityComparer that uses
        // the CaseInsensitiveComparer.DefaultInvariant to determine equality.
        Hashtable myHT2 = new Hashtable(3, new myCultureComparer());
        myHT2.Add("FIRST", "Hello");
        myHT2.Add("SECOND", "World");
        myHT2.Add("THIRD", "!");

        // Create a hash table using an IEqualityComparer that is based on
        // the Turkish culture (tr-TR) where "I" is not the uppercase
        // version of "i".
        CultureInfo myCul = new CultureInfo("tr-TR");
        Hashtable myHT3 = new Hashtable(3, new myCultureComparer(myCul));
        myHT3.Add("FIRST", "Hello");
        myHT3.Add("SECOND", "World");
        myHT3.Add("THIRD", "!");

        // Search for a key in each hash table.
        Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"));
        Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"));
        Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"));

    }

}


/* 
This code produces the following output.
Results vary depending on the system's culture settings.

first is in myHT1: False
first is in myHT2: True
first is in myHT3: False

*/

Imports System
Imports System.Collections
Imports System.Globalization

Public Class myCultureComparer
    Implements IEqualityComparer

    Dim myComparer As CaseInsensitiveComparer

    Public Sub New()
        myComparer = CaseInsensitiveComparer.DefaultInvariant
    End Sub

    Public Sub New(ByVal myCulture As CultureInfo)
        myComparer = New CaseInsensitiveComparer(myCulture)
    End Sub

    Public Function Equals1(ByVal x As Object, ByVal y As Object) _
        As Boolean Implements IEqualityComparer.Equals

        If (myComparer.Compare(x, y) = 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function GetHashCode1(ByVal obj As Object) _
        As Integer Implements IEqualityComparer.GetHashCode
        Return obj.ToString().ToLower().GetHashCode()
    End Function
End Class

Public Class SamplesHashtable   

   Public Shared Sub Main()

      ' Create a hash table using the default comparer.
      Dim myHT1 As New Hashtable(3)
      myHT1.Add("FIRST", "Hello")
      myHT1.Add("SECOND", "World")
      myHT1.Add("THIRD", "!")

      ' Create a hash table using the specified IEqualityComparer that uses
      ' the CaseInsensitiveComparer.DefaultInvariant to determine equality.
      Dim myHT2 As New Hashtable(3, New myCultureComparer())
      myHT2.Add("FIRST", "Hello")
      myHT2.Add("SECOND", "World")
      myHT2.Add("THIRD", "!")

      ' Create a hash table using an IEqualityComparer that is based on
      ' the Turkish culture (tr-TR) where "I" is not the uppercase
      ' version of "i".
      Dim myCul As New CultureInfo("tr-TR")
      Dim myHT3 As New Hashtable(3, New myCultureComparer(myCul))
      myHT3.Add("FIRST", "Hello")
      myHT3.Add("SECOND", "World")
      myHT3.Add("THIRD", "!")

      ' Search for a key in each hash table.
      Console.WriteLine("first is in myHT1: {0}", myHT1.ContainsKey("first"))
      Console.WriteLine("first is in myHT2: {0}", myHT2.ContainsKey("first"))
      Console.WriteLine("first is in myHT3: {0}", myHT3.ContainsKey("first"))

   End Sub 'Main 

End Class 'SamplesHashtable


'This code produces the following output.
'Results vary depending on the system's culture settings.
'
'first is in myHT1: False
'first is in myHT2: True
'first is in myHT3: False

설명

여러 요소를 추가 하는 동안 크기 조정 작업을 수행할 필요가 없습니다 초기 용량을 지정 하는 Hashtable 개체입니다.Specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the Hashtable object. 용량을 자동으로 부하 비율에 따라 필요에 따라 증가 합니다.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.

실제 로드 비율과 지정된 된 로드 비율에 도달 하면 현재 버킷 수가 두 번 보다 큰 가장 작은 소수를 버킷 수가 자동으로 증가 합니다.When the actual load factor reaches the specified load factor, the number of buckets is automatically increased to the smallest prime number that is larger than twice the current number of buckets.

IEqualityComparer 개체 해시 코드 공급자 및 비교자를 모두 포함 됩니다.The IEqualityComparer object includes both the hash code provider and the comparer. 경우는 IEqualityComparer 에 사용 되는 Hashtable 생성자, 개체에서 키로 사용 합니다 Hashtable 재정의할 필요가 없습니다를 Object.GetHashCodeObject.Equals 메서드.If an IEqualityComparer is used in the Hashtable constructor, the objects used as keys in the Hashtable are not required to override the Object.GetHashCode and Object.Equals methods.

키에 대 한 해시 코드를 분배 하는 해시 코드 공급자는 Hashtable합니다.The hash code provider dispenses hash codes for keys in the Hashtable. 기본 해시 코드 공급자는 키의 구현의 Object.GetHashCode합니다.The default hash code provider is the key's implementation of Object.GetHashCode.

두 키가 같은지 여부를 결정 하는 비교자입니다.The comparer determines whether two keys are equal. 모든 키를 Hashtable 고유 해야 합니다.Every key in a Hashtable must be unique. 기본 비교자는 키의 구현의 Object.Equals합니다.The default comparer is the key's implementation of Object.Equals.

IEqualityComparer 대/소문자 문자열을 사용 하 여 조회를 수행 하는 시나리오도 가능 합니다.The IEqualityComparer enables scenarios such as doing lookups with case-insensitive strings.

이 생성자는 (n) 작업, 여기서 ncapacity 매개 변수입니다.This constructor is an O(n) operation, where n is the capacity parameter.

추가 정보

적용 대상