DictionaryBase 클래스

정의

강력한 형식의 키/값 쌍 컬렉션에 대한 abstract 기본 클래스를 제공합니다.

public ref class DictionaryBase abstract : System::Collections::IDictionary
public abstract class DictionaryBase : System.Collections.IDictionary
[System.Serializable]
public abstract class DictionaryBase : System.Collections.IDictionary
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class DictionaryBase : System.Collections.IDictionary
type DictionaryBase = class
    interface ICollection
    interface IEnumerable
    interface IDictionary
[<System.Serializable>]
type DictionaryBase = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DictionaryBase = class
    interface IDictionary
    interface ICollection
    interface IEnumerable
Public MustInherit Class DictionaryBase
Implements IDictionary
상속
DictionaryBase
파생
특성
구현

예제

다음 코드 예제에서는 구현 합니다 DictionaryBase 클래스 및 5 자 이하의 키와 값의 String 사전을 Length 만드는 해당 구현을 사용 합니다.

using namespace System;
using namespace System::Collections;

public ref class ShortStringDictionary: public DictionaryBase
{
public:

   property String^ Item [String^]
   {
      String^ get( String^ key )
      {
         return (dynamic_cast<String^>(Dictionary[ key ]));
      }

      void set( String^ value, String^ key )
      {
         Dictionary[ key ] = value;
      }
   }

   property ICollection^ Keys 
   {
      ICollection^ get()
      {
         return (Dictionary->Keys);
      }
   }

   property ICollection^ Values 
   {
      ICollection^ get()
      {
         return (Dictionary->Values);
      }
   }
   void Add( String^ key, String^ value )
   {
      Dictionary->Add( key, value );
   }

   bool Contains( String^ key )
   {
      return (Dictionary->Contains( key ));
   }

   void Remove( String^ key )
   {
      Dictionary->Remove( key );
   }


protected:
   virtual void OnInsert( Object^ key, Object^ value ) override
   {
      if ( key->GetType() != Type::GetType( "System.String" ) )
            throw gcnew ArgumentException( "key must be of type String.","key" );
      else
      {
         String^ strKey = dynamic_cast<String^>(key);
         if ( strKey->Length > 5 )
                  throw gcnew ArgumentException( "key must be no more than 5 characters in length.","key" );
      }

      if ( value->GetType() != Type::GetType( "System.String" ) )
            throw gcnew ArgumentException( "value must be of type String.","value" );
      else
      {
         String^ strValue = dynamic_cast<String^>(value);
         if ( strValue->Length > 5 )
                  throw gcnew ArgumentException( "value must be no more than 5 characters in length.","value" );
      }
   }

   virtual void OnRemove( Object^ key, Object^ /*value*/ ) override
   {
      if ( key->GetType() != Type::GetType( "System.String" ) )
            throw gcnew ArgumentException( "key must be of type String.","key" );
      else
      {
         String^ strKey = dynamic_cast<String^>(key);
         if ( strKey->Length > 5 )
                  throw gcnew ArgumentException( "key must be no more than 5 characters in length.","key" );
      }
   }

   virtual void OnSet( Object^ key, Object^ /*oldValue*/, Object^ newValue ) override
   {
      if ( key->GetType() != Type::GetType( "System.String" ) )
            throw gcnew ArgumentException( "key must be of type String.","key" );
      else
      {
         String^ strKey = dynamic_cast<String^>(key);
         if ( strKey->Length > 5 )
                  throw gcnew ArgumentException( "key must be no more than 5 characters in length.","key" );
      }

      if ( newValue->GetType() != Type::GetType( "System.String" ) )
            throw gcnew ArgumentException( "newValue must be of type String.","newValue" );
      else
      {
         String^ strValue = dynamic_cast<String^>(newValue);
         if ( strValue->Length > 5 )
                  throw gcnew ArgumentException( "newValue must be no more than 5 characters in length.","newValue" );
      }
   }

   virtual void OnValidate( Object^ key, Object^ value ) override
   {
      if ( key->GetType() != Type::GetType( "System.String" ) )
            throw gcnew ArgumentException( "key must be of type String.","key" );
      else
      {
         String^ strKey = dynamic_cast<String^>(key);
         if ( strKey->Length > 5 )
                  throw gcnew ArgumentException( "key must be no more than 5 characters in length.","key" );
      }

      if ( value->GetType() != Type::GetType( "System.String" ) )
            throw gcnew ArgumentException( "value must be of type String.","value" );
      else
      {
         String^ strValue = dynamic_cast<String^>(value);
         if ( strValue->Length > 5 )
                  throw gcnew ArgumentException( "value must be no more than 5 characters in length.","value" );
      }
   }

};

void PrintKeysAndValues2( ShortStringDictionary^ myCol );
void PrintKeysAndValues3( ShortStringDictionary^ myCol );
int main()
{
   // Creates and initializes a new DictionaryBase.
   ShortStringDictionary^ mySSC = gcnew ShortStringDictionary;

   // Adds elements to the collection.
   mySSC->Add( "One", "a" );
   mySSC->Add( "Two", "ab" );
   mySSC->Add( "Three", "abc" );
   mySSC->Add( "Four", "abcd" );
   mySSC->Add( "Five", "abcde" );

   // Display the contents of the collection using the enumerator.
   Console::WriteLine( "Contents of the collection (using enumerator):" );
   PrintKeysAndValues2( mySSC );

   // Display the contents of the collection using the Keys property and the Item property.
   Console::WriteLine( "Initial contents of the collection (using Keys and Item):" );
   PrintKeysAndValues3( mySSC );

   // Tries to add a value that is too long.
   try
   {
      mySSC->Add( "Ten", "abcdefghij" );
   }
   catch ( ArgumentException^ e ) 
   {
      Console::WriteLine( e );
   }

   // Tries to add a key that is too long.
   try
   {
      mySSC->Add( "Eleven", "ijk" );
   }
   catch ( ArgumentException^ e ) 
   {
      Console::WriteLine( e );
   }

   Console::WriteLine();

   // Searches the collection with Contains.
   Console::WriteLine( "Contains \"Three\": {0}", mySSC->Contains( "Three" ) );
   Console::WriteLine( "Contains \"Twelve\": {0}", mySSC->Contains( "Twelve" ) );
   Console::WriteLine();

   // Removes an element from the collection.
   mySSC->Remove( "Two" );

   // Displays the contents of the collection.
   Console::WriteLine( "After removing \"Two\":" );
   PrintKeysAndValues2( mySSC );
}

// Uses the enumerator. 
void PrintKeysAndValues2( ShortStringDictionary^ myCol )
{
   DictionaryEntry myDE;
   System::Collections::IEnumerator^ myEnumerator = myCol->GetEnumerator();
   while ( myEnumerator->MoveNext() )
      if ( myEnumerator->Current != nullptr )
   {
      myDE =  *dynamic_cast<DictionaryEntry^>(myEnumerator->Current);
      Console::WriteLine( "   {0,-5} : {1}", myDE.Key, myDE.Value );
   }

   Console::WriteLine();
}


// Uses the Keys property and the Item property.
void PrintKeysAndValues3( ShortStringDictionary^ myCol )
{
   ICollection^ myKeys = myCol->Keys;
   IEnumerator^ myEnum1 = myKeys->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      String^ k = safe_cast<String^>(myEnum1->Current);
      Console::WriteLine( "   {0,-5} : {1}", k, myCol->Item[ k ] );
   }

   Console::WriteLine();
}

/* 
This code produces the following output.

Contents of the collection (using enumerator):
   Three : abc
   Five  : abcde
   Two   : ab
   One   : a
   Four  : abcd

Initial contents of the collection (using Keys and Item):
   Three : abc
   Five  : abcde
   Two   : ab
   One   : a
   Four  : abcd

System.ArgumentException: value must be no more than 5 characters in length.
Parameter name: value
   at ShortStringDictionary.OnValidate(Object key, Object value)
   at System.Collections.DictionaryBase.System.Collections.IDictionary.Add(Object key, Object value)
   at SamplesDictionaryBase.Main()
System.ArgumentException: key must be no more than 5 characters in length.
Parameter name: key
   at ShortStringDictionary.OnValidate(Object key, Object value)
   at System.Collections.DictionaryBase.System.Collections.IDictionary.Add(Object key, Object value)
   at SamplesDictionaryBase.Main()

Contains "Three": True
Contains "Twelve": False

After removing "Two":
   Three : abc
   Five  : abcde
   One   : a
   Four  : abcd

*/
using System;
using System.Collections;

public class ShortStringDictionary : DictionaryBase  {

   public String this[ String key ]  {
      get  {
         return( (String) Dictionary[key] );
      }
      set  {
         Dictionary[key] = value;
      }
   }

   public ICollection Keys  {
      get  {
         return( Dictionary.Keys );
      }
   }

   public ICollection Values  {
      get  {
         return( Dictionary.Values );
      }
   }

   public void Add( String key, String value )  {
      Dictionary.Add( key, value );
   }

   public bool Contains( String key )  {
      return( Dictionary.Contains( key ) );
   }

   public void Remove( String key )  {
      Dictionary.Remove( key );
   }

   protected override void OnInsert( Object key, Object value )  {
      if ( key.GetType() != typeof(System.String) )
        {
            throw new ArgumentException( "key must be of type String.", "key" );
        }
        else  {
         String strKey = (String) key;
         if ( strKey.Length > 5 )
            throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
      }

      if ( value.GetType() != typeof(System.String) )
        {
            throw new ArgumentException( "value must be of type String.", "value" );
        }
        else  {
         String strValue = (String) value;
         if ( strValue.Length > 5 )
            throw new ArgumentException( "value must be no more than 5 characters in length.", "value" );
      }
   }

   protected override void OnRemove( Object key, Object value )  {
      if ( key.GetType() != typeof(System.String) )
        {
            throw new ArgumentException( "key must be of type String.", "key" );
        }
        else  {
         String strKey = (String) key;
         if ( strKey.Length > 5 )
            throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
      }
   }

   protected override void OnSet( Object key, Object oldValue, Object newValue )  {
      if ( key.GetType() != typeof(System.String) )
        {
            throw new ArgumentException( "key must be of type String.", "key" );
        }
        else  {
         String strKey = (String) key;
         if ( strKey.Length > 5 )
            throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
      }

      if ( newValue.GetType() != typeof(System.String) )
        {
            throw new ArgumentException( "newValue must be of type String.", "newValue" );
        }
        else  {
         String strValue = (String) newValue;
         if ( strValue.Length > 5 )
            throw new ArgumentException( "newValue must be no more than 5 characters in length.", "newValue" );
      }
   }

   protected override void OnValidate( Object key, Object value )  {
      if ( key.GetType() != typeof(System.String) )
        {
            throw new ArgumentException( "key must be of type String.", "key" );
        }
        else  {
         String strKey = (String) key;
         if ( strKey.Length > 5 )
            throw new ArgumentException( "key must be no more than 5 characters in length.", "key" );
      }

      if ( value.GetType() != typeof(System.String) )
        {
            throw new ArgumentException( "value must be of type String.", "value" );
        }
        else  {
         String strValue = (String) value;
         if ( strValue.Length > 5 )
            throw new ArgumentException( "value must be no more than 5 characters in length.", "value" );
      }
   }
}

public class SamplesDictionaryBase  {

   public static void Main()  {

      // Creates and initializes a new DictionaryBase.
      ShortStringDictionary mySSC = new ShortStringDictionary();

      // Adds elements to the collection.
      mySSC.Add( "One", "a" );
      mySSC.Add( "Two", "ab" );
      mySSC.Add( "Three", "abc" );
      mySSC.Add( "Four", "abcd" );
      mySSC.Add( "Five", "abcde" );

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

      // Display the contents of the collection using the enumerator.
      Console.WriteLine( "Contents of the collection (using enumerator):" );
      PrintKeysAndValues2( mySSC );

      // Display the contents of the collection using the Keys property and the Item property.
      Console.WriteLine( "Initial contents of the collection (using Keys and Item):" );
      PrintKeysAndValues3( mySSC );

      // Tries to add a value that is too long.
      try  {
         mySSC.Add( "Ten", "abcdefghij" );
      }
      catch ( ArgumentException e )  {
         Console.WriteLine( e.ToString() );
      }

      // Tries to add a key that is too long.
      try  {
         mySSC.Add( "Eleven", "ijk" );
      }
      catch ( ArgumentException e )  {
         Console.WriteLine( e.ToString() );
      }

      Console.WriteLine();

      // Searches the collection with Contains.
      Console.WriteLine( "Contains \"Three\": {0}", mySSC.Contains( "Three" ) );
      Console.WriteLine( "Contains \"Twelve\": {0}", mySSC.Contains( "Twelve" ) );
      Console.WriteLine();

      // Removes an element from the collection.
      mySSC.Remove( "Two" );

      // Displays the contents of the collection.
      Console.WriteLine( "After removing \"Two\":" );
      PrintKeysAndValues1( mySSC );
   }

   // 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( ShortStringDictionary myCol )  {
      foreach ( DictionaryEntry myDE in myCol )
         Console.WriteLine( "   {0,-5} : {1}", myDE.Key, myDE.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( ShortStringDictionary myCol )  {
      DictionaryEntry myDE;
      System.Collections.IEnumerator myEnumerator = myCol.GetEnumerator();
      while ( myEnumerator.MoveNext() )
         if ( myEnumerator.Current != null )  {
            myDE = (DictionaryEntry) myEnumerator.Current;
            Console.WriteLine( "   {0,-5} : {1}", myDE.Key, myDE.Value );
         }
      Console.WriteLine();
   }

   // Uses the Keys property and the Item property.
   public static void PrintKeysAndValues3( ShortStringDictionary myCol )  {
      ICollection myKeys = myCol.Keys;
      foreach ( String k in myKeys )
         Console.WriteLine( "   {0,-5} : {1}", k, myCol[k] );
      Console.WriteLine();
   }
}


/*
This code produces the following output.

Contents of the collection (using foreach):
   Three : abc
   Five  : abcde
   Two   : ab
   One   : a
   Four  : abcd

Contents of the collection (using enumerator):
   Three : abc
   Five  : abcde
   Two   : ab
   One   : a
   Four  : abcd

Initial contents of the collection (using Keys and Item):
   Three : abc
   Five  : abcde
   Two   : ab
   One   : a
   Four  : abcd

System.ArgumentException: value must be no more than 5 characters in length.
Parameter name: value
   at ShortStringDictionary.OnValidate(Object key, Object value)
   at System.Collections.DictionaryBase.System.Collections.IDictionary.Add(Object key, Object value)
   at SamplesDictionaryBase.Main()
System.ArgumentException: key must be no more than 5 characters in length.
Parameter name: key
   at ShortStringDictionary.OnValidate(Object key, Object value)
   at System.Collections.DictionaryBase.System.Collections.IDictionary.Add(Object key, Object value)
   at SamplesDictionaryBase.Main()

Contains "Three": True
Contains "Twelve": False

After removing "Two":
   Three : abc
   Five  : abcde
   One   : a
   Four  : abcd

*/
Imports System.Collections

Public Class ShortStringDictionary
   Inherits DictionaryBase

   Default Public Property Item(key As String) As String
      Get
         Return CType(Dictionary(key), String)
      End Get
      Set
         Dictionary(key) = value
      End Set
   End Property

   Public ReadOnly Property Keys() As ICollection
      Get
         Return Dictionary.Keys
      End Get
   End Property

   Public ReadOnly Property Values() As ICollection
      Get
         Return Dictionary.Values
      End Get
   End Property

   Public Sub Add(key As String, value As String)
      Dictionary.Add(key, value)
   End Sub

   Public Function Contains(key As String) As Boolean
      Return Dictionary.Contains(key)
   End Function 'Contains

   Public Sub Remove(key As String)
      Dictionary.Remove(key)
   End Sub

   Protected Overrides Sub OnInsert(key As Object, value As Object)
      If Not GetType(System.String).IsAssignableFrom(key.GetType()) Then
         Throw New ArgumentException("key must be of type String.", "key")
      Else
         Dim strKey As String = CType(key, String)
         If strKey.Length > 5 Then
            Throw New ArgumentException("key must be no more than 5 characters in length.", "key")
         End If
      End If 
      If Not GetType(System.String).IsAssignableFrom(value.GetType()) Then
         Throw New ArgumentException("value must be of type String.", "value")
      Else
         Dim strValue As String = CType(value, String)
         If strValue.Length > 5 Then
            Throw New ArgumentException("value must be no more than 5 characters in length.", "value")
         End If
      End If
   End Sub

   Protected Overrides Sub OnRemove(key As Object, value As Object)
      If Not GetType(System.String).IsAssignableFrom(key.GetType()) Then
         Throw New ArgumentException("key must be of type String.", "key")
      Else
         Dim strKey As String = CType(key, String)
         If strKey.Length > 5 Then
            Throw New ArgumentException("key must be no more than 5 characters in length.", "key")
         End If
      End If
   End Sub

   Protected Overrides Sub OnSet(key As Object, oldValue As Object, newValue As Object)
      If Not GetType(System.String).IsAssignableFrom(key.GetType()) Then
         Throw New ArgumentException("key must be of type String.", "key")
      Else
         Dim strKey As String = CType(key, String)
         If strKey.Length > 5 Then
            Throw New ArgumentException("key must be no more than 5 characters in length.", "key")
         End If
      End If 
      If Not GetType(System.String).IsAssignableFrom(newValue.GetType()) Then
         Throw New ArgumentException("newValue must be of type String.", "newValue")
      Else
         Dim strValue As String = CType(newValue, String)
         If strValue.Length > 5 Then
            Throw New ArgumentException("newValue must be no more than 5 characters in length.", "newValue")
         End If
      End If
   End Sub

   Protected Overrides Sub OnValidate(key As Object, value As Object)
      If Not GetType(System.String).IsAssignableFrom(key.GetType()) Then
         Throw New ArgumentException("key must be of type String.", "key")
      Else
         Dim strKey As String = CType(key, String)
         If strKey.Length > 5 Then
            Throw New ArgumentException("key must be no more than 5 characters in length.", "key")
         End If
      End If 
      If Not GetType(System.String).IsAssignableFrom(value.GetType()) Then
         Throw New ArgumentException("value must be of type String.", "value")
      Else
         Dim strValue As String = CType(value, String)
         If strValue.Length > 5 Then
            Throw New ArgumentException("value must be no more than 5 characters in length.", "value")
         End If
      End If
   End Sub

End Class


Public Class SamplesDictionaryBase

   Public Shared Sub Main()

      ' Creates and initializes a new DictionaryBase.
      Dim mySSC As New ShortStringDictionary()

      ' Adds elements to the collection.
      mySSC.Add("One", "a")
      mySSC.Add("Two", "ab")
      mySSC.Add("Three", "abc")
      mySSC.Add("Four", "abcd")
      mySSC.Add("Five", "abcde")

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

      ' Display the contents of the collection using the enumerator.
      Console.WriteLine("Contents of the collection (using enumerator):")
      PrintKeysAndValues2(mySSC)

      ' Display the contents of the collection using the Keys property and the Item property.
      Console.WriteLine("Initial contents of the collection (using Keys and Item):")
      PrintKeysAndValues3(mySSC)

      ' Tries to add a value that is too long.
      Try
          mySSC.Add("Ten", "abcdefghij")
      Catch e As ArgumentException
          Console.WriteLine(e.ToString())
      End Try

      ' Tries to add a key that is too long.
      Try
          mySSC.Add("Eleven", "ijk")
      Catch e As ArgumentException
          Console.WriteLine(e.ToString())
      End Try

      Console.WriteLine()

      ' Searches the collection with Contains.
      Console.WriteLine("Contains ""Three"": {0}", mySSC.Contains("Three"))
      Console.WriteLine("Contains ""Twelve"": {0}", mySSC.Contains("Twelve"))
      Console.WriteLine()

      ' Removes an element from the collection.
      mySSC.Remove("Two")

      ' Displays the contents of the collection.
      Console.WriteLine("After removing ""Two"":")
      PrintKeysAndValues1(mySSC)

    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 ShortStringDictionary)
      Dim myDE As DictionaryEntry
      For Each myDE In  myCol
          Console.WriteLine("   {0,-5} : {1}", myDE.Key, myDE.Value)
      Next myDE
      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 ShortStringDictionary)
      Dim myDE As DictionaryEntry
      Dim myEnumerator As System.Collections.IEnumerator = myCol.GetEnumerator()
      While myEnumerator.MoveNext()
          If Not (myEnumerator.Current Is Nothing) Then
            myDE = CType(myEnumerator.Current, DictionaryEntry)
            Console.WriteLine("   {0,-5} : {1}", myDE.Key, myDE.Value)
          End If
      End While
      Console.WriteLine()
    End Sub


    ' Uses the Keys property and the Item property.
    Public Shared Sub PrintKeysAndValues3(myCol As ShortStringDictionary)
      Dim myKeys As ICollection = myCol.Keys
      Dim k As String
      For Each k In  myKeys
          Console.WriteLine("   {0,-5} : {1}", k, myCol(k))
      Next k
      Console.WriteLine()
    End Sub

End Class


'This code produces the following output.
'
'Contents of the collection (using For Each):
'   Three : abc
'   Five  : abcde
'   Two   : ab
'   One   : a
'   Four  : abcd
'
'Contents of the collection (using enumerator):
'   Three : abc
'   Five  : abcde
'   Two   : ab
'   One   : a
'   Four  : abcd
'
'Initial contents of the collection (using Keys and Item):
'   Three : abc
'   Five  : abcde
'   Two   : ab
'   One   : a
'   Four  : abcd
'
'System.ArgumentException: value must be no more than 5 characters in length.
'Parameter name: value
'   at ShortStringDictionary.OnValidate(Object key, Object value)
'   at System.Collections.DictionaryBase.System.Collections.IDictionary.Add(Object key, Object value)
'   at SamplesDictionaryBase.Main()
'System.ArgumentException: key must be no more than 5 characters in length.
'Parameter name: key
'   at ShortStringDictionary.OnValidate(Object key, Object value)
'   at System.Collections.DictionaryBase.System.Collections.IDictionary.Add(Object key, Object value)
'   at SamplesDictionaryBase.Main()
'
'Contains "Three": True
'Contains "Twelve": False
'
'After removing "Two":
'   Three : abc
'   Five  : abcde
'   One   : a
'   Four  : abcd

설명

중요

새 개발에 클래스를 DictionaryBase 사용하지 않는 것이 좋습니다. 대신 제네릭 Dictionary<TKey,TValue> 또는 KeyedCollection<TKey,TItem> 클래스 를 사용하는 것이 좋습니다. 자세한 내용은 GitHub에서 제네릭이 아닌 컬렉션을 사용하면 안 됨 을 참조하세요.

C# foreach 문과 Visual Basic For Each 문은 컬렉션에 있는 요소 형식의 개체를 반환합니다. 의 DictionaryBase 각 요소는 키/값 쌍이므로 요소 형식은 키의 형식이나 값 형식이 아닙니다. 대신 요소 형식은 입니다 DictionaryEntry.

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

참고

키를 상속하고 동작을 변경할 수 있으므로 메서드를 사용한 비교를 통해 Equals 절대 고유성을 보장할 수 없습니다.

구현자 참고

이 기본 클래스는 구현자가 강력한 형식의 사용자 지정 컬렉션을 쉽게 만들 수 있도록 하기 위해 제공됩니다. 구현자는 자체 클래스를 만드는 대신 이 기본 클래스를 확장하는 것이 좋습니다.

이 기본 클래스의 멤버는 보호되며 파생 클래스를 통해서만 사용됩니다.

생성자

DictionaryBase()

DictionaryBase 클래스의 새 인스턴스를 초기화합니다.

속성

Count

DictionaryBase 인스턴스에 포함된 요소 수를 가져옵니다.

Dictionary

DictionaryBase 인스턴스에 포함된 요소의 목록을 가져옵니다.

InnerHashtable

DictionaryBase 인스턴스에 포함된 요소의 목록을 가져옵니다.

메서드

Clear()

DictionaryBase 인스턴스의 콘텐츠를 지웁니다.

CopyTo(Array, Int32)

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

Equals(Object)

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

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

IDictionaryEnumerator 인스턴스를 반복하는 DictionaryBase를 반환합니다.

GetHashCode()

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

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

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

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

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

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

DictionaryBase 인스턴스의 내용을 지우기 전에 추가로 사용자 지정 프로세스를 수행합니다.

OnClearComplete()

DictionaryBase 인스턴스의 내용을 지운 후에 추가로 사용자 지정 프로세스를 수행합니다.

OnGet(Object, Object)

DictionaryBase 인스턴스에서 지정한 키와 값이 있는 요소를 가져옵니다.

OnInsert(Object, Object)

DictionaryBase 인스턴스에 새 요소를 삽입하기 전에 추가로 사용자 지정 프로세스를 수행합니다.

OnInsertComplete(Object, Object)

DictionaryBase 인스턴스에 새 요소를 삽입한 후에 추가로 사용자 지정 프로세스를 수행합니다.

OnRemove(Object, Object)

DictionaryBase 인스턴스에서 요소를 제거하기 전에 추가로 사용자 지정 프로세스를 수행합니다.

OnRemoveComplete(Object, Object)

DictionaryBase 인스턴스에서 요소를 제거한 후에 추가로 사용자 지정 프로세스를 수행합니다.

OnSet(Object, Object, Object)

DictionaryBase 인스턴스에 값을 설정하기 전에 추가로 사용자 지정 프로세스를 수행합니다.

OnSetComplete(Object, Object, Object)

DictionaryBase 인스턴스에 값을 설정한 후에 추가로 사용자 지정 프로세스를 수행합니다.

OnValidate(Object, Object)

지정한 키와 값을 가지는 요소의 유효성을 검사할 때 추가로 사용자 지정 프로세스를 수행합니다.

ToString()

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.IsSynchronized

DictionaryBase 개체에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지 여부를 나타내는 값을 가져옵니다.

ICollection.SyncRoot

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

IDictionary.Add(Object, Object)

지정한 키와 값을 가지는 요소를 DictionaryBase에 추가합니다.

IDictionary.Contains(Object)

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

IDictionary.IsFixedSize

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

IDictionary.IsReadOnly

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

IDictionary.Item[Object]

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

IDictionary.Keys

ICollection 개체의 키가 포함된 DictionaryBase 개체를 가져옵니다.

IDictionary.Remove(Object)

DictionaryBase에서 지정한 키를 가지는 요소를 제거합니다.

IDictionary.Values

ICollection 개체의 값이 포함된 DictionaryBase 개체를 가져옵니다.

IEnumerable.GetEnumerator()

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

확장 메서드

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

스레드 보안

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

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

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

추가 정보