HybridDictionary 클래스

정의

컬렉션이 작을 때는 ListDictionary를 사용하여 IDictionary를 구현한 다음 컬렉션이 커지면 Hashtable로 전환합니다.

public ref class HybridDictionary : System::Collections::IDictionary
public class HybridDictionary : System.Collections.IDictionary
[System.Serializable]
public class HybridDictionary : System.Collections.IDictionary
type HybridDictionary = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
[<System.Serializable>]
type HybridDictionary = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
Public Class HybridDictionary
Implements IDictionary
상속
HybridDictionary
파생
특성
구현

예제

다음 코드 예제에서는 몇 가지 속성 및 메서드를 HybridDictionary보여 줍니다.

#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;

void PrintKeysAndValues1( IDictionary^ myCol );
void PrintKeysAndValues2( IDictionary^ myCol );
void PrintKeysAndValues3( HybridDictionary^ myCol );
int main()
{
   
   // Creates and initializes a new HybridDictionary.
   HybridDictionary^ myCol = gcnew HybridDictionary;
   myCol->Add( "Braeburn Apples", "1.49" );
   myCol->Add( "Fuji Apples", "1.29" );
   myCol->Add( "Gala Apples", "1.49" );
   myCol->Add( "Golden Delicious Apples", "1.29" );
   myCol->Add( "Granny Smith Apples", "0.89" );
   myCol->Add( "Red Delicious Apples", "0.99" );
   myCol->Add( "Plantain Bananas", "1.49" );
   myCol->Add( "Yellow Bananas", "0.79" );
   myCol->Add( "Strawberries", "3.33" );
   myCol->Add( "Cranberries", "5.98" );
   myCol->Add( "Navel Oranges", "1.29" );
   myCol->Add( "Grapes", "1.99" );
   myCol->Add( "Honeydew Melon", "0.59" );
   myCol->Add( "Seedless Watermelon", "0.49" );
   myCol->Add( "Pineapple", "1.49" );
   myCol->Add( "Nectarine", "1.99" );
   myCol->Add( "Plums", "1.69" );
   myCol->Add( "Peaches", "1.99" );

   // Display the contents of the collection using for each. This is the preferred method.
   Console::WriteLine( "Displays the elements using for each:" );
   PrintKeysAndValues1( myCol );

   // Display the contents of the collection using the enumerator.
   Console::WriteLine( "Displays the elements using the IDictionaryEnumerator:" );
   PrintKeysAndValues2( myCol );

   // Display the contents of the collection using the Keys, Values, Count, and Item properties.
   Console::WriteLine( "Displays the elements using the Keys, Values, Count, and Item properties:" );
   PrintKeysAndValues3( myCol );

   // Copies the HybridDictionary to an array with DictionaryEntry elements.
   array<DictionaryEntry>^myArr = gcnew array<DictionaryEntry>(myCol->Count);
   myCol->CopyTo( myArr, 0 );

   // Displays the values in the array.
   Console::WriteLine( "Displays the elements in the array:" );
   Console::WriteLine( "   KEY                       VALUE" );
   for ( int i = 0; i < myArr->Length; i++ )
      Console::WriteLine( "   {0,-25} {1}", myArr[ i ].Key, myArr[ i ].Value );
   Console::WriteLine();

   // Searches for a key.
   if ( myCol->Contains( "Kiwis" ) )
      Console::WriteLine( "The collection contains the key \"Kiwis\"." );
   else
      Console::WriteLine( "The collection does not contain the key \"Kiwis\"." );

   Console::WriteLine();

   // Deletes a key.
   myCol->Remove( "Plums" );
   Console::WriteLine( "The collection contains the following elements after removing \"Plums\":" );
   PrintKeysAndValues1( myCol );

   // Clears the entire collection.
   myCol->Clear();
   Console::WriteLine( "The collection contains the following elements after it is cleared:" );
   PrintKeysAndValues1( myCol );
}

// Uses the for each statement which hides the complexity of the enumerator.
// NOTE: The for each statement is the preferred way of enumerating the contents of a collection.
void PrintKeysAndValues1( IDictionary^ myCol )  {
   Console::WriteLine( "   KEY                       VALUE" );
   for each ( DictionaryEntry^ de in myCol )
      Console::WriteLine( "   {0,-25} {1}", de->Key, de->Value );
   Console::WriteLine();
}

// Uses the enumerator. 
void PrintKeysAndValues2( IDictionary^ myCol )
{
   IDictionaryEnumerator^ myEnumerator = myCol->GetEnumerator();
   Console::WriteLine( "   KEY                       VALUE" );
   while ( myEnumerator->MoveNext() )
      Console::WriteLine( "   {0,-25} {1}", myEnumerator->Key, myEnumerator->Value );

   Console::WriteLine();
}

// Uses the Keys, Values, Count, and Item properties.
void PrintKeysAndValues3( HybridDictionary^ myCol )
{
   array<String^>^myKeys = gcnew array<String^>(myCol->Count);
   myCol->Keys->CopyTo( myKeys, 0 );
   Console::WriteLine( "   INDEX KEY                       VALUE" );
   for ( int i = 0; i < myCol->Count; i++ )
      Console::WriteLine( "   {0,-5} {1,-25} {2}", i, myKeys[ i ], myCol[ myKeys[ i ] ] );
   Console::WriteLine();
}

/*
This code produces output similar to the following:

Displays the elements using for each:
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Plums                     1.69
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

Displays the elements using the IDictionaryEnumerator:
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Plums                     1.69
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

Displays the elements using the Keys, Values, Count, and Item properties:
   INDEX KEY                       VALUE
   0     Strawberries              3.33
   1     Yellow Bananas            0.79
   2     Cranberries               5.98
   3     Grapes                    1.99
   4     Granny Smith Apples       0.89
   5     Seedless Watermelon       0.49
   6     Honeydew Melon            0.59
   7     Red Delicious Apples      0.99
   8     Navel Oranges             1.29
   9     Fuji Apples               1.29
   10    Plantain Bananas          1.49
   11    Gala Apples               1.49
   12    Pineapple                 1.49
   13    Plums                     1.69
   14    Braeburn Apples           1.49
   15    Peaches                   1.99
   16    Golden Delicious Apples   1.29
   17    Nectarine                 1.99

Displays the elements in the array:
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Plums                     1.69
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

The collection does not contain the key "Kiwis".

The collection contains the following elements after removing "Plums":
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

The collection contains the following elements after it is cleared:
   KEY                       VALUE

*/
using System;
using System.Collections;
using System.Collections.Specialized;

public class SamplesHybridDictionary  {

   public static void Main()  {

      // Creates and initializes a new HybridDictionary.
      HybridDictionary myCol = new HybridDictionary();
      myCol.Add( "Braeburn Apples", "1.49" );
      myCol.Add( "Fuji Apples", "1.29" );
      myCol.Add( "Gala Apples", "1.49" );
      myCol.Add( "Golden Delicious Apples", "1.29" );
      myCol.Add( "Granny Smith Apples", "0.89" );
      myCol.Add( "Red Delicious Apples", "0.99" );
      myCol.Add( "Plantain Bananas", "1.49" );
      myCol.Add( "Yellow Bananas", "0.79" );
      myCol.Add( "Strawberries", "3.33" );
      myCol.Add( "Cranberries", "5.98" );
      myCol.Add( "Navel Oranges", "1.29" );
      myCol.Add( "Grapes", "1.99" );
      myCol.Add( "Honeydew Melon", "0.59" );
      myCol.Add( "Seedless Watermelon", "0.49" );
      myCol.Add( "Pineapple", "1.49" );
      myCol.Add( "Nectarine", "1.99" );
      myCol.Add( "Plums", "1.69" );
      myCol.Add( "Peaches", "1.99" );

      // Display the contents of the collection using foreach. This is the preferred method.
      Console.WriteLine( "Displays the elements using foreach:" );
      PrintKeysAndValues1( myCol );

      // Display the contents of the collection using the enumerator.
      Console.WriteLine( "Displays the elements using the IDictionaryEnumerator:" );
      PrintKeysAndValues2( myCol );

      // Display the contents of the collection using the Keys, Values, Count, and Item properties.
      Console.WriteLine( "Displays the elements using the Keys, Values, Count, and Item properties:" );
      PrintKeysAndValues3( myCol );

      // Copies the HybridDictionary to an array with DictionaryEntry elements.
      DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];
      myCol.CopyTo( myArr, 0 );

      // Displays the values in the array.
      Console.WriteLine( "Displays the elements in the array:" );
      Console.WriteLine( "   KEY                       VALUE" );
      for ( int i = 0; i < myArr.Length; i++ )
         Console.WriteLine( "   {0,-25} {1}", myArr[i].Key, myArr[i].Value );
      Console.WriteLine();

      // Searches for a key.
      if ( myCol.Contains( "Kiwis" ) )
         Console.WriteLine( "The collection contains the key \"Kiwis\"." );
      else
         Console.WriteLine( "The collection does not contain the key \"Kiwis\"." );
      Console.WriteLine();

      // Deletes a key.
      myCol.Remove( "Plums" );
      Console.WriteLine( "The collection contains the following elements after removing \"Plums\":" );
      PrintKeysAndValues1( myCol );

      // Clears the entire collection.
      myCol.Clear();
      Console.WriteLine( "The collection contains the following elements after it is cleared:" );
      PrintKeysAndValues1( myCol );
   }

   // Uses the foreach statement which hides the complexity of the enumerator.
   // NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.
   public static void PrintKeysAndValues1( IDictionary myCol )  {
      Console.WriteLine( "   KEY                       VALUE" );
      foreach ( DictionaryEntry de in myCol )
         Console.WriteLine( "   {0,-25} {1}", de.Key, de.Value );
      Console.WriteLine();
   }

   // Uses the enumerator.
   // NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.
   public static void PrintKeysAndValues2( IDictionary myCol )  {
      IDictionaryEnumerator myEnumerator = myCol.GetEnumerator();
      Console.WriteLine( "   KEY                       VALUE" );
      while ( myEnumerator.MoveNext() )
         Console.WriteLine( "   {0,-25} {1}", myEnumerator.Key, myEnumerator.Value );
      Console.WriteLine();
   }

   // Uses the Keys, Values, Count, and Item properties.
   public static void PrintKeysAndValues3( HybridDictionary myCol )  {
      String[] myKeys = new String[myCol.Count];
      myCol.Keys.CopyTo( myKeys, 0 );

      Console.WriteLine( "   INDEX KEY                       VALUE" );
      for ( int i = 0; i < myCol.Count; i++ )
         Console.WriteLine( "   {0,-5} {1,-25} {2}", i, myKeys[i], myCol[myKeys[i]] );
      Console.WriteLine();
   }
}

/*
This code produces output similar to the following:

Displays the elements using foreach:
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Plums                     1.69
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

Displays the elements using the IDictionaryEnumerator:
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Plums                     1.69
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

Displays the elements using the Keys, Values, Count, and Item properties:
   INDEX KEY                       VALUE
   0     Strawberries              3.33
   1     Yellow Bananas            0.79
   2     Cranberries               5.98
   3     Grapes                    1.99
   4     Granny Smith Apples       0.89
   5     Seedless Watermelon       0.49
   6     Honeydew Melon            0.59
   7     Red Delicious Apples      0.99
   8     Navel Oranges             1.29
   9     Fuji Apples               1.29
   10    Plantain Bananas          1.49
   11    Gala Apples               1.49
   12    Pineapple                 1.49
   13    Plums                     1.69
   14    Braeburn Apples           1.49
   15    Peaches                   1.99
   16    Golden Delicious Apples   1.29
   17    Nectarine                 1.99

Displays the elements in the array:
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Plums                     1.69
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

The collection does not contain the key "Kiwis".

The collection contains the following elements after removing "Plums":
   KEY                       VALUE
   Strawberries              3.33
   Yellow Bananas            0.79
   Cranberries               5.98
   Grapes                    1.99
   Granny Smith Apples       0.89
   Seedless Watermelon       0.49
   Honeydew Melon            0.59
   Red Delicious Apples      0.99
   Navel Oranges             1.29
   Fuji Apples               1.29
   Plantain Bananas          1.49
   Gala Apples               1.49
   Pineapple                 1.49
   Braeburn Apples           1.49
   Peaches                   1.99
   Golden Delicious Apples   1.29
   Nectarine                 1.99

The collection contains the following elements after it is cleared:
   KEY                       VALUE

*/
Imports System.Collections
Imports System.Collections.Specialized

Public Class SamplesHybridDictionary   

   Public Shared Sub Main()

      ' Creates and initializes a new HybridDictionary.
      Dim myCol As New HybridDictionary()
      myCol.Add("Braeburn Apples", "1.49")
      myCol.Add("Fuji Apples", "1.29")
      myCol.Add("Gala Apples", "1.49")
      myCol.Add("Golden Delicious Apples", "1.29")
      myCol.Add("Granny Smith Apples", "0.89")
      myCol.Add("Red Delicious Apples", "0.99")
      myCol.Add("Plantain Bananas", "1.49")
      myCol.Add("Yellow Bananas", "0.79")
      myCol.Add("Strawberries", "3.33")
      myCol.Add("Cranberries", "5.98")
      myCol.Add("Navel Oranges", "1.29")
      myCol.Add("Grapes", "1.99")
      myCol.Add("Honeydew Melon", "0.59")
      myCol.Add("Seedless Watermelon", "0.49")
      myCol.Add("Pineapple", "1.49")
      myCol.Add("Nectarine", "1.99")
      myCol.Add("Plums", "1.69")
      myCol.Add("Peaches", "1.99")

      ' Display the contents of the collection using For Each. This is the preferred method.
      Console.WriteLine("Displays the elements using For Each:")
      PrintKeysAndValues1(myCol)

      ' Display the contents of the collection using the enumerator.
      Console.WriteLine("Displays the elements using the IDictionaryEnumerator:")
      PrintKeysAndValues2(myCol)

      ' Display the contents of the collection using the Keys, Values, Count, and Item properties.
      Console.WriteLine("Displays the elements using the Keys, Values, Count, and Item properties:")
      PrintKeysAndValues3(myCol)

      ' Copies the HybridDictionary to an array with DictionaryEntry elements.
      Dim myArr(myCol.Count) As DictionaryEntry
      myCol.CopyTo(myArr, 0)

      ' Displays the values in the array.
      Console.WriteLine("Displays the elements in the array:")
      Console.WriteLine("   KEY                       VALUE")
      Dim i As Integer
      For i = 0 To myArr.Length - 1
         Console.WriteLine("   {0,-25} {1}", myArr(i).Key, myArr(i).Value)
      Next i
      Console.WriteLine()

      ' Searches for a key.
      If myCol.Contains("Kiwis") Then
         Console.WriteLine("The collection contains the key ""Kiwis"".")
      Else
         Console.WriteLine("The collection does not contain the key ""Kiwis"".")
      End If
      Console.WriteLine()

      ' Deletes a key.
      myCol.Remove("Plums")
      Console.WriteLine("The collection contains the following elements after removing ""Plums"":")
      PrintKeysAndValues1(myCol)

      ' Clears the entire collection.
      myCol.Clear()
      Console.WriteLine("The collection contains the following elements after it is cleared:")
      PrintKeysAndValues1(myCol)

   End Sub

   ' Uses the For Each statement which hides the complexity of the enumerator.
   ' NOTE: The For Each statement is the preferred way of enumerating the contents of a collection.
   Public Shared Sub PrintKeysAndValues1(myCol As IDictionary)

      Console.WriteLine("   KEY                       VALUE")
      Dim de As DictionaryEntry
      For Each de In  myCol
         Console.WriteLine("   {0,-25} {1}", de.Key, de.Value)
      Next de
      Console.WriteLine()

   End Sub


   ' Uses the enumerator. 
   ' NOTE: The For Each statement is the preferred way of enumerating the contents of a collection.
   Public Shared Sub PrintKeysAndValues2(myCol As IDictionary)
      Dim myEnumerator As IDictionaryEnumerator = myCol.GetEnumerator()

      Console.WriteLine("   KEY                       VALUE")
      While myEnumerator.MoveNext()
         Console.WriteLine("   {0,-25} {1}", myEnumerator.Key, myEnumerator.Value)
      End While
      Console.WriteLine()

   End Sub


   ' Uses the Keys, Values, Count, and Item properties.
   Public Shared Sub PrintKeysAndValues3(myCol As HybridDictionary)
      Dim myKeys(myCol.Count) As [String]
      myCol.Keys.CopyTo(myKeys, 0)

      Console.WriteLine("   INDEX KEY                       VALUE")
      Dim i As Integer
      For i = 0 To myCol.Count - 1
         Console.WriteLine("   {0,-5} {1,-25} {2}", i, myKeys(i), myCol(myKeys(i)))
      Next i
      Console.WriteLine()

   End Sub

End Class


'This code produces output similar to the following:
'
'Displays the elements using For Each:
'   KEY                       VALUE
'   Strawberries              3.33
'   Yellow Bananas            0.79
'   Cranberries               5.98
'   Grapes                    1.99
'   Granny Smith Apples       0.89
'   Seedless Watermelon       0.49
'   Honeydew Melon            0.59
'   Red Delicious Apples      0.99
'   Navel Oranges             1.29
'   Fuji Apples               1.29
'   Plantain Bananas          1.49
'   Gala Apples               1.49
'   Pineapple                 1.49
'   Plums                     1.69
'   Braeburn Apples           1.49
'   Peaches                   1.99
'   Golden Delicious Apples   1.29
'   Nectarine                 1.99
'
'Displays the elements using the IDictionaryEnumerator:
'   KEY                       VALUE
'   Strawberries              3.33
'   Yellow Bananas            0.79
'   Cranberries               5.98
'   Grapes                    1.99
'   Granny Smith Apples       0.89
'   Seedless Watermelon       0.49
'   Honeydew Melon            0.59
'   Red Delicious Apples      0.99
'   Navel Oranges             1.29
'   Fuji Apples               1.29
'   Plantain Bananas          1.49
'   Gala Apples               1.49
'   Pineapple                 1.49
'   Plums                     1.69
'   Braeburn Apples           1.49
'   Peaches                   1.99
'   Golden Delicious Apples   1.29
'   Nectarine                 1.99
'
'Displays the elements using the Keys, Values, Count, and Item properties:
'   INDEX KEY                       VALUE
'   0     Strawberries              3.33
'   1     Yellow Bananas            0.79
'   2     Cranberries               5.98
'   3     Grapes                    1.99
'   4     Granny Smith Apples       0.89
'   5     Seedless Watermelon       0.49
'   6     Honeydew Melon            0.59
'   7     Red Delicious Apples      0.99
'   8     Navel Oranges             1.29
'   9     Fuji Apples               1.29
'   10    Plantain Bananas          1.49
'   11    Gala Apples               1.49
'   12    Pineapple                 1.49
'   13    Plums                     1.69
'   14    Braeburn Apples           1.49
'   15    Peaches                   1.99
'   16    Golden Delicious Apples   1.29
'   17    Nectarine                 1.99
'
'Displays the elements in the array:
'   KEY                       VALUE
'   Strawberries              3.33
'   Yellow Bananas            0.79
'   Cranberries               5.98
'   Grapes                    1.99
'   Granny Smith Apples       0.89
'   Seedless Watermelon       0.49
'   Honeydew Melon            0.59
'   Red Delicious Apples      0.99
'   Navel Oranges             1.29
'   Fuji Apples               1.29
'   Plantain Bananas          1.49
'   Gala Apples               1.49
'   Pineapple                 1.49
'   Plums                     1.69
'   Braeburn Apples           1.49
'   Peaches                   1.99
'   Golden Delicious Apples   1.29
'   Nectarine                 1.99
'
'The collection does not contain the key "Kiwis".
'
'The collection contains the following elements after removing "Plums":
'   KEY                       VALUE
'   Strawberries              3.33
'   Yellow Bananas            0.79
'   Cranberries               5.98
'   Grapes                    1.99
'   Granny Smith Apples       0.89
'   Seedless Watermelon       0.49
'   Honeydew Melon            0.59
'   Red Delicious Apples      0.99
'   Navel Oranges             1.29
'   Fuji Apples               1.29
'   Plantain Bananas          1.49
'   Gala Apples               1.49
'   Pineapple                 1.49
'   Braeburn Apples           1.49
'   Peaches                   1.99
'   Golden Delicious Apples   1.29
'   Nectarine                 1.99
'
'The collection contains the following elements after it is cleared:
'   KEY                       VALUE

설명

사전의 요소 수를 알 수 없는 경우 이 클래스를 사용하는 것이 좋습니다. 작은 컬렉션의 ListDictionary 향상된 성능을 활용하고 더 큰 컬렉션을 보다 잘 ListDictionary처리하는 컬렉션으로 Hashtable 유연하게 전환할 수 있습니다.

컬렉션의 초기 크기가 최적 크기ListDictionary보다 크면 요소를 복사하는 오버헤드를 방지하기 위해 컬렉션이 ListDictionary Hashtable저장 Hashtable 됩니다.

생성자는 사용자가 문자열을 비교할 때 컬렉션이 대/소문자를 무시할지 여부를 지정할 수 있는 부울 매개 변수를 허용합니다. 컬렉션이 대/소문자를 구분하는 경우 키의 구현 및 Object.GetHashCode Object.Equals. 컬렉션이 대/소문자를 구분하지 않는 경우 단순 서수 대/소문자를 구분하지 않는 비교를 수행하여 고정 문화권의 대/소문자 구분 규칙을 준수합니다. 기본적으로 컬렉션은 대/소문자를 구분합니다. 고정 문화권에 대한 자세한 내용은 다음을 참조하세요 System.Globalization.CultureInfo.

키는 null일 수 없지만 값은 null일 수 있습니다.

C# 언어(For EachVisual Basic)의 문은 foreach 컬렉션에 있는 요소 형식의 개체를 반환합니다. 각 요소는 HybridDictionary 키/값 쌍이므로 요소 형식은 키의 형식이나 값의 형식이 아닙니다. 대신 요소 형식은 .입니다 DictionaryEntry. 예를 들면 다음과 같습니다.

for each (DictionaryEntry^ de in myHybridDictionary)
{
    //...
}
foreach (DictionaryEntry de in myHybridDictionary)
{
    //...
}
For Each de In myHybridDictionary
    '...
Next

foreach 문은 열거자 주위의 래퍼로, 컬렉션에서 쓰는 것이 아니라 읽는 것만 허용합니다.

생성자

HybridDictionary()

대/소문자를 구분하는 빈 HybridDictionary를 만듭니다.

HybridDictionary(Boolean)

대/소문자 구분이 지정된 빈 HybridDictionary를 만듭니다.

HybridDictionary(Int32)

처음 크기가 지정된 대/소문자를 구분하는 HybridDictionary를 만듭니다.

HybridDictionary(Int32, Boolean)

처음 크기와 대/소문자 구분 여부가 지정된 HybridDictionary를 만듭니다.

속성

Count

HybridDictionary에 포함된 키/값 쌍의 수를 가져옵니다.

IsFixedSize

HybridDictionary의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IsReadOnly

HybridDictionary가 읽기 전용인지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

HybridDictionary가 동기화되어 스레드로부터 안전하게 보호되는지 여부를 나타내는 값을 가져옵니다.

Item[Object]

지정된 키에 연결된 값을 가져오거나 설정합니다.

Keys

ICollection의 키를 포함하는 HybridDictionary을 가져옵니다.

SyncRoot

HybridDictionary에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

Values

ICollection의 값이 들어 있는 HybridDictionary을 가져옵니다.

메서드

Add(Object, Object)

지정한 키와 값을 가지는 엔트리를 HybridDictionary에 추가합니다.

Clear()

HybridDictionary에서 모든 엔트리를 제거합니다.

Contains(Object)

HybridDictionary에 특정 키가 들어 있는지 여부를 확인합니다.

CopyTo(Array, Int32)

지정한 인덱스에서 HybridDictionary 엔트리를 1차원 Array 인스턴스에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

IDictionaryEnumerator를 반복하는 HybridDictionary를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(Object)

HybridDictionary에서 지정한 키를 가지는 엔트리를 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

IEnumerable.GetEnumerator()

IEnumerator를 반복하는 HybridDictionary를 반환합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

스레드 보안

공용 정적 (Shared Visual Basic의)이 형식의 멤버는 스레드로부터 안전 합니다. 인스턴스 구성원은 스레드로부터의 안전성이 보장되지 않습니다.

이 구현은 동기화된(스레드로부터 안전한) 래퍼를 HybridDictionary제공하지 않지만 파생 클래스는 속성을 사용하여 SyncRoot 자체 동기화된 버전을 HybridDictionary 만들 수 있습니다.

컬렉션 전체를 열거하는 프로시저는 기본적으로 스레드로부터 안전하지 않습니다. 컬렉션이 동기화되어 있을 때 다른 스레드에서 해당 컬렉션을 수정할 수 있으므로 이렇게 되면 열거자에서 예외가 throw됩니다. 열거하는 동안 스레드로부터 안전을 보장하려면 전체 열거를 수행하는 동안 컬렉션을 잠그거나 다른 스레드에서 변경된 내용으로 인해 발생한 예외를 catch하면 됩니다.

추가 정보