IDictionary 인터페이스

정의

키/값 쌍의 제네릭이 아닌 컬렉션을 나타냅니다.

public interface class IDictionary : System::Collections::ICollection
public interface IDictionary : System.Collections.ICollection
[System.Runtime.InteropServices.ComVisible(true)]
public interface IDictionary : System.Collections.ICollection
type IDictionary = interface
    interface ICollection
    interface IEnumerable
[<System.Runtime.InteropServices.ComVisible(true)>]
type IDictionary = interface
    interface ICollection
    interface IEnumerable
Public Interface IDictionary
Implements ICollection
파생
특성
구현

예제

다음 코드 예제에서는 인터페이스를 구현 하는 간단한 사전 클래스를 정의 하는 방법을 보여 줍니다 IDictionary .

using namespace System;
using namespace System::Collections;

// This class implements a simple dictionary using an array of
// DictionaryEntry objects (key/value pairs).
public ref class SimpleDictionary : public IDictionary
{
    // The array of items
private:
    array<DictionaryEntry^>^ items;
private:
    int itemsInUse;

    // Construct the SimpleDictionary with the desired number of
    // items. The number of items cannot change for the life time of
    // this SimpleDictionary.
public:
    SimpleDictionary(int size)
    {
        items = gcnew array<DictionaryEntry^>(size);
    }

    #pragma region IDictionary Members
public:
    property virtual bool IsReadOnly
    {
        bool get()
        {
            return false;
        }
    }
public:
    virtual bool Contains(Object^ key)
    {
        int index;
        return TryGetIndexOfKey(key, &index);
    }
public:
    virtual property bool IsFixedSize
    {
        bool get()
        {
            return false;
        }
    }
public:
    virtual void Remove(Object^ key)
    {
        if (key == nullptr)
        {
            throw gcnew ArgumentNullException("key");
        }
        // Try to find the key in the DictionaryEntry array
        int index;
        if (TryGetIndexOfKey(key, &index))
        {
            // If the key is found, slide all the items down.
            Array::Copy(items, index + 1, items, index, itemsInUse -
                index - 1);
            itemsInUse--;
        }
        else
        {
            // If the key is not in the dictionary, just return.
            return;
        }
    }
public:
    virtual void Clear()
    {
        itemsInUse = 0;
    }
public:
    virtual void Add(Object^ key, Object^ value)
    {
        // Add the new key/value pair even if this key already exists
        // in the dictionary.
        if (itemsInUse == items->Length)
        {
            throw gcnew InvalidOperationException
                ("The dictionary cannot hold any more items.");
        }
        items[itemsInUse++] = gcnew DictionaryEntry(key, value);
    }
public:
    virtual property ICollection^ Keys
    {
        ICollection^ get()
        {
            // Return an array where each item is a key.
            array<Object^>^ keys = gcnew array<Object^>(itemsInUse);
            for (int i = 0; i < itemsInUse; i++)
            {
                keys[i] = items[i]->Key;
            }
            return keys;
        }
    }
public:
    virtual property ICollection^ Values
    {
        ICollection^ get()
        {
            // Return an array where each item is a value.
            array<Object^>^ values = gcnew array<Object^>(itemsInUse);
            for (int i = 0; i < itemsInUse; i++)
            {
                values[i] = items[i]->Value;
            }
            return values;
        }
    }
public:
    virtual property Object^ default[Object^]
    {
        Object^ get(Object^ key)
        {
            // If this key is in the dictionary, return its value.
            int index;
            if (TryGetIndexOfKey(key, &index))
            {
                // The key was found; return its value.
                return items[index]->Value;
            }
            else
            {
                // The key was not found; return null.
                return nullptr;
            }
        }

        void set(Object^ key, Object^ value)
        {
            // If this key is in the dictionary, change its value.
            int index;
            if (TryGetIndexOfKey(key, &index))
            {
                // The key was found; change its value.
                items[index]->Value = value;
            }
            else
            {
                // This key is not in the dictionary; add this
                // key/value pair.
                Add(key, value);
            }
        }
    }
private:
    bool TryGetIndexOfKey(Object^ key, int* index)
    {
        for (*index = 0; *index < itemsInUse; *index++)
        {
            // If the key is found, return true (the index is also
            // returned).
            if (items[*index]->Key->Equals(key))
            {
                return true;
            }
        }

        // Key not found, return false (index should be ignored by
        // the caller).
        return false;
    }
private:
    ref class SimpleDictionaryEnumerator : public IDictionaryEnumerator
    {
        // A copy of the SimpleDictionary object's key/value pairs.
private:
        array<DictionaryEntry^>^ items;
private:
        int index;

public:
        SimpleDictionaryEnumerator(SimpleDictionary^ sd)
        {
            // Make a copy of the dictionary entries currently in the
            // SimpleDictionary object.
            items = gcnew array<DictionaryEntry^>(sd->Count);
            Array::Copy(sd->items, 0, items, 0, sd->Count);
            index = -1;
        }

        // Return the current item.
public:
        virtual property Object^ Current
        {
            Object^ get()
            {
                ValidateIndex();
                return items[index];
            }
        }

        // Return the current dictionary entry.
public:
        virtual property DictionaryEntry Entry
        {
            DictionaryEntry get()
            {
                return (DictionaryEntry) Current;
            }
        }

        // Return the key of the current item.
public:
        virtual property Object^ Key
        {
            Object^ get()
            {
                ValidateIndex();
                return items[index]->Key;
            }
        }

        // Return the value of the current item.
public:
        virtual property Object^ Value
        {
            Object^ get()
            {
                ValidateIndex();
                return items[index]->Value;
            }
        }

        // Advance to the next item.
public:
        virtual bool MoveNext()
        {
            if (index < items->Length - 1)
            {
                index++;
                return true;
            }
            return false;
        }

        // Validate the enumeration index and throw an exception if
        // the index is out of range.
private:
        void ValidateIndex()
        {
            if (index < 0 || index >= items->Length)
            {
                throw gcnew InvalidOperationException
                    ("Enumerator is before or after the collection.");
            }
        }

        // Reset the index to restart the enumeration.
public:
        virtual void Reset()
        {
            index = -1;
        }
    };
public:
    virtual IDictionaryEnumerator^ GetEnumerator()
    {
        // Construct and return an enumerator.
        return gcnew SimpleDictionaryEnumerator(this);
    }
    #pragma endregion

    #pragma region ICollection Members
public:
    virtual property bool IsSynchronized
    {
        bool get()
        {
            return false;
        }
    }

public:
    virtual property Object^ SyncRoot
    {
        Object^ get()
        {
            throw gcnew NotImplementedException();
        }
    }

public:
    virtual property int Count
    {
        int get()
        {
            return itemsInUse;
        }
    }

public:
    virtual void CopyTo(Array^ array, int index)
    {
        throw gcnew NotImplementedException();
    }
    #pragma endregion

    #pragma region IEnumerable Members

    virtual IEnumerator^ IEnumerable_GetEnumerator() 
        = IEnumerable::GetEnumerator
    {
        // Construct and return an enumerator.
        return ((IDictionary^)this)->GetEnumerator();
    }
    #pragma endregion
};

int main()
{
    // Create a dictionary that contains no more than three
    // entries.
    IDictionary^ d = gcnew SimpleDictionary(3);

    // Add three people and their ages to the dictionary.
    d->Add("Jeff", 40);
    d->Add("Kristin", 34);
    d->Add("Aidan", 1);

    Console::WriteLine("Number of elements in dictionary = {0}",
        d->Count);

    Console::WriteLine("Does dictionary contain 'Jeff'? {0}",
        d->Contains("Jeff"));
    Console::WriteLine("Jeff's age is {0}", d["Jeff"]);

    // Display every entry's key and value.
    for each (DictionaryEntry^ de in d)
    {
        Console::WriteLine("{0} is {1} years old.", de->Key,
            de->Value);
    }

    // Remove an entry that exists.
    d->Remove("Jeff");

    // Remove an entry that does not exist, but do not throw an
    // exception.
    d->Remove("Max");

    // Show the names (keys) of the people in the dictionary.
    for each (String^ s in d->Keys)
    {
        Console::WriteLine(s);
    }

    // Show the ages (values) of the people in the dictionary.
    for each (int age in d->Values)
    {
        Console::WriteLine(age);
    }
}

// This code produces the following output.
//
// Number of elements in dictionary = 3
// Does dictionary contain 'Jeff'? True
// Jeff's age is 40
// Jeff is 40 years old.
// Kristin is 34 years old.
// Aidan is 1 years old.
// Kristin
// Aidan
// 34
// 1
using System;
using System.Collections;

// This class implements a simple dictionary using an array of DictionaryEntry objects (key/value pairs).
public class SimpleDictionary : IDictionary
{
    // The array of items
    private DictionaryEntry[] items;
    private Int32 ItemsInUse = 0;

    // Construct the SimpleDictionary with the desired number of items.
    // The number of items cannot change for the life time of this SimpleDictionary.
    public SimpleDictionary(Int32 numItems)
    {
        items = new DictionaryEntry[numItems];
    }

    #region IDictionary Members
    public bool IsReadOnly { get { return false; } }
    public bool Contains(object key)
    {
       Int32 index;
       return TryGetIndexOfKey(key, out index);
    }
    public bool IsFixedSize { get { return false; } }
    public void Remove(object key)
    {
        if (key == null) throw new ArgumentNullException("key");
        // Try to find the key in the DictionaryEntry array
        Int32 index;
        if (TryGetIndexOfKey(key, out index))
        {
            // If the key is found, slide all the items up.
            Array.Copy(items, index + 1, items, index, ItemsInUse - index - 1);
            ItemsInUse--;
        }
        else
        {
            // If the key is not in the dictionary, just return.
        }
    }
    public void Clear() { ItemsInUse = 0; }
    public void Add(object key, object value)
    {
        // Add the new key/value pair even if this key already exists in the dictionary.
        if (ItemsInUse == items.Length)
            throw new InvalidOperationException("The dictionary cannot hold any more items.");
        items[ItemsInUse++] = new DictionaryEntry(key, value);
    }
    public ICollection Keys
    {
        get
        {
            // Return an array where each item is a key.
            Object[] keys = new Object[ItemsInUse];
            for (Int32 n = 0; n < ItemsInUse; n++)
                keys[n] = items[n].Key;
            return keys;
        }
    }
    public ICollection Values
    {
        get
        {
            // Return an array where each item is a value.
            Object[] values = new Object[ItemsInUse];
            for (Int32 n = 0; n < ItemsInUse; n++)
                values[n] = items[n].Value;
            return values;
        }
    }
    public object this[object key]
    {
        get
        {
            // If this key is in the dictionary, return its value.
            Int32 index;
            if (TryGetIndexOfKey(key, out index))
            {
                // The key was found; return its value.
                return items[index].Value;
            }
            else
            {
                // The key was not found; return null.
                return null;
            }
        }

        set
        {
            // If this key is in the dictionary, change its value.
            Int32 index;
            if (TryGetIndexOfKey(key, out index))
            {
                // The key was found; change its value.
                items[index].Value = value;
            }
            else
            {
                // This key is not in the dictionary; add this key/value pair.
                Add(key, value);
            }
        }
    }
    private Boolean TryGetIndexOfKey(Object key, out Int32 index)
    {
        for (index = 0; index < ItemsInUse; index++)
        {
            // If the key is found, return true (the index is also returned).
            if (items[index].Key.Equals(key)) return true;
        }

        // Key not found, return false (index should be ignored by the caller).
        return false;
    }
    private class SimpleDictionaryEnumerator : IDictionaryEnumerator
    {
        // A copy of the SimpleDictionary object's key/value pairs.
        DictionaryEntry[] items;
        Int32 index = -1;

        public SimpleDictionaryEnumerator(SimpleDictionary sd)
        {
            // Make a copy of the dictionary entries currently in the SimpleDictionary object.
            items = new DictionaryEntry[sd.Count];
            Array.Copy(sd.items, 0, items, 0, sd.Count);
        }

        // Return the current item.
        public Object Current { get { ValidateIndex(); return items[index]; } }

        // Return the current dictionary entry.
        public DictionaryEntry Entry
        {
            get { return (DictionaryEntry) Current; }
        }

        // Return the key of the current item.
        public Object Key { get { ValidateIndex();  return items[index].Key; } }

        // Return the value of the current item.
        public Object Value { get { ValidateIndex();  return items[index].Value; } }

        // Advance to the next item.
        public Boolean MoveNext()
        {
            if (index < items.Length - 1) { index++; return true; }
            return false;
        }

        // Validate the enumeration index and throw an exception if the index is out of range.
        private void ValidateIndex()
        {
            if (index < 0 || index >= items.Length)
            throw new InvalidOperationException("Enumerator is before or after the collection.");
        }

        // Reset the index to restart the enumeration.
        public void Reset()
        {
            index = -1;
        }
    }
    public IDictionaryEnumerator GetEnumerator()
    {
        // Construct and return an enumerator.
        return new SimpleDictionaryEnumerator(this);
    }
    #endregion

    #region ICollection Members
    public bool IsSynchronized { get { return false; } }
    public object SyncRoot { get { throw new NotImplementedException(); } }
    public int Count { get { return ItemsInUse; } }
    public void CopyTo(Array array, int index) { throw new NotImplementedException(); }
    #endregion

    #region IEnumerable Members
    IEnumerator IEnumerable.GetEnumerator()
    {
        // Construct and return an enumerator.
        return ((IDictionary)this).GetEnumerator();
    }
    #endregion
}

public sealed class App
{
    static void Main()
    {
        // Create a dictionary that contains no more than three entries.
        IDictionary d = new SimpleDictionary(3);

        // Add three people and their ages to the dictionary.
        d.Add("Jeff", 40);
        d.Add("Kristin", 34);
        d.Add("Aidan", 1);

        Console.WriteLine("Number of elements in dictionary = {0}", d.Count);

        Console.WriteLine("Does dictionary contain 'Jeff'? {0}", d.Contains("Jeff"));
        Console.WriteLine("Jeff's age is {0}", d["Jeff"]);

        // Display every entry's key and value.
        foreach (DictionaryEntry de in d)
        {
            Console.WriteLine("{0} is {1} years old.", de.Key, de.Value);
        }

        // Remove an entry that exists.
        d.Remove("Jeff");

        // Remove an entry that does not exist, but do not throw an exception.
        d.Remove("Max");

        // Show the names (keys) of the people in the dictionary.
        foreach (String s in d.Keys)
            Console.WriteLine(s);

        // Show the ages (values) of the people in the dictionary.
        foreach (Int32 age in d.Values)
            Console.WriteLine(age);
    }
}

// This code produces the following output.
//
// Number of elements in dictionary = 3
// Does dictionary contain 'Jeff'? True
// Jeff's age is 40
// Jeff is 40 years old.
// Kristin is 34 years old.
// Aidan is 1 years old.
// Kristin
// Aidan
// 34
// 1
Imports System.Collections

' This class implements a simple dictionary using an array of DictionaryEntry objects (key/value pairs).
Public Class SimpleDictionary
    Implements IDictionary

    ' The array of items
    Dim items() As DictionaryEntry
    Dim ItemsInUse As Integer = 0

    ' Construct the SimpleDictionary with the desired number of items.
    ' The number of items cannot change for the life time of this SimpleDictionary.
    Public Sub New(ByVal numItems As Integer)
        items = New DictionaryEntry(numItems - 1) {}
    End Sub

    ' IDictionary Members
    Public ReadOnly Property IsReadOnly() As Boolean Implements IDictionary.IsReadOnly
        Get
            Return False
        End Get
    End Property

    Public Function Contains(ByVal key As Object) As Boolean Implements IDictionary.Contains
        Dim index As Integer
        Return TryGetIndexOfKey(key, index)
    End Function

    Public ReadOnly Property IsFixedSize() As Boolean Implements IDictionary.IsFixedSize
        Get
            Return False
        End Get
    End Property

    Public Sub Remove(ByVal key As Object) Implements IDictionary.Remove
        If key = Nothing Then
            Throw New ArgumentNullException("key")
        End If
        ' Try to find the key in the DictionaryEntry array
        Dim index As Integer
        If TryGetIndexOfKey(key, index) Then

            ' If the key is found, slide all the items up.
            Array.Copy(items, index + 1, items, index, (ItemsInUse - index) - 1)
            ItemsInUse = ItemsInUse - 1
        Else

            ' If the key is not in the dictionary, just return. 
        End If
    End Sub

    Public Sub Clear() Implements IDictionary.Clear
        ItemsInUse = 0
    End Sub

    Public Sub Add(ByVal key As Object, ByVal value As Object) Implements IDictionary.Add

        ' Add the new key/value pair even if this key already exists in the dictionary.
        If ItemsInUse = items.Length Then
            Throw New InvalidOperationException("The dictionary cannot hold any more items.")
        End If
        items(ItemsInUse) = New DictionaryEntry(key, value)
        ItemsInUse = ItemsInUse + 1
    End Sub

    Public ReadOnly Property Keys() As ICollection Implements IDictionary.Keys
        Get

            ' Return an array where each item is a key.
            ' Note: Declaring keyArray() to have a size of ItemsInUse - 1
            '       ensures that the array is properly sized, in VB.NET
            '       declaring an array of size N creates an array with
            '       0 through N elements, including N, as opposed to N - 1
            '       which is the default behavior in C# and C++.
            Dim keyArray() As Object = New Object(ItemsInUse - 1) {}
            Dim n As Integer
            For n = 0 To ItemsInUse - 1
                keyArray(n) = items(n).Key
            Next n

            Return keyArray
        End Get
    End Property

    Public ReadOnly Property Values() As ICollection Implements IDictionary.Values
        Get
            ' Return an array where each item is a value.
            Dim valueArray() As Object = New Object(ItemsInUse - 1) {}
            Dim n As Integer
            For n = 0 To ItemsInUse - 1
                valueArray(n) = items(n).Value
            Next n

            Return valueArray
        End Get
    End Property

    Public Property Item(ByVal key As Object) As Object Implements IDictionary.Item
        Get

            ' If this key is in the dictionary, return its value.
            Dim index As Integer
            If TryGetIndexOfKey(key, index) Then

                ' The key was found return its value.
                Return items(index).Value
            Else

                ' The key was not found return null.
                Return Nothing
            End If
        End Get

        Set(ByVal value As Object)
            ' If this key is in the dictionary, change its value. 
            Dim index As Integer
            If TryGetIndexOfKey(key, index) Then

                ' The key was found change its value.
                items(index).Value = value
            Else

                ' This key is not in the dictionary add this key/value pair.
                Add(key, value)
            End If
        End Set
    End Property

    Private Function TryGetIndexOfKey(ByVal key As Object, ByRef index As Integer) As Boolean
        For index = 0 To ItemsInUse - 1
            ' If the key is found, return true (the index is also returned).
            If items(index).Key.Equals(key) Then
                Return True
            End If
        Next index

        ' Key not found, return false (index should be ignored by the caller).
        Return False
    End Function

    Private Class SimpleDictionaryEnumerator
        Implements IDictionaryEnumerator

        ' A copy of the SimpleDictionary object's key/value pairs.
        Dim items() As DictionaryEntry
        Dim index As Integer = -1

        Public Sub New(ByVal sd As SimpleDictionary)
            ' Make a copy of the dictionary entries currently in the SimpleDictionary object.
            items = New DictionaryEntry(sd.Count - 1) {}
            Array.Copy(sd.items, 0, items, 0, sd.Count)
        End Sub

        ' Return the current item.
        Public ReadOnly Property Current() As Object Implements IDictionaryEnumerator.Current
            Get
                ValidateIndex()
                Return items(index)
            End Get
        End Property

        ' Return the current dictionary entry.
        Public ReadOnly Property Entry() As DictionaryEntry Implements IDictionaryEnumerator.Entry
            Get
                Return Current
            End Get
        End Property

        ' Return the key of the current item.
        Public ReadOnly Property Key() As Object Implements IDictionaryEnumerator.Key
            Get
                ValidateIndex()
                Return items(index).Key
            End Get
        End Property

        ' Return the value of the current item.
        Public ReadOnly Property Value() As Object Implements IDictionaryEnumerator.Value
            Get
                ValidateIndex()
                Return items(index).Value
            End Get
        End Property

        ' Advance to the next item.
        Public Function MoveNext() As Boolean Implements IDictionaryEnumerator.MoveNext
            If index < items.Length - 1 Then
                index = index + 1
                Return True
            End If

            Return False
        End Function

        ' Validate the enumeration index and throw an exception if the index is out of range.
        Private Sub ValidateIndex()
            If index < 0 Or index >= items.Length Then
                Throw New InvalidOperationException("Enumerator is before or after the collection.")
            End If
        End Sub

        ' Reset the index to restart the enumeration.
        Public Sub Reset() Implements IDictionaryEnumerator.Reset
            index = -1
        End Sub

    End Class

    Public Function GetEnumerator() As IDictionaryEnumerator Implements IDictionary.GetEnumerator

        'Construct and return an enumerator.
        Return New SimpleDictionaryEnumerator(Me)
    End Function


    ' ICollection Members
    Public ReadOnly Property IsSynchronized() As Boolean Implements IDictionary.IsSynchronized
        Get
            Return False
        End Get
    End Property

    Public ReadOnly Property SyncRoot() As Object Implements IDictionary.SyncRoot
        Get
            Throw New NotImplementedException()
        End Get
    End Property

    Public ReadOnly Property Count() As Integer Implements IDictionary.Count
        Get
            Return ItemsInUse
        End Get
    End Property

    Public Sub CopyTo(ByVal array As Array, ByVal index As Integer) Implements IDictionary.CopyTo
        Throw New NotImplementedException()
    End Sub

    ' IEnumerable Members
    Public Function GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator

        ' Construct and return an enumerator.
        Return Me.GetEnumerator()
    End Function
End Class

Public NotInheritable Class App
    Public Shared Sub Main()
        ' Create a dictionary that contains no more than three entries.
        Dim d As IDictionary = New SimpleDictionary(3)

        ' Add three people and their ages to the dictionary.
        d.Add("Jeff", 40)
        d.Add("Kristin", 34)
        d.Add("Aidan", 1)

        Console.WriteLine("Number of elements in dictionary = {0}", d.Count)

        Console.WriteLine("Does dictionary contain 'Jeff'? {0}", d.Contains("Jeff"))
        Console.WriteLine("Jeff's age is {0}", d("Jeff"))

        ' Display every entry's key and value.
        Dim de As DictionaryEntry
        For Each de In d
            Console.WriteLine("{0} is {1} years old.", de.Key, de.Value)
        Next

        ' Remove an entry that exists.
        d.Remove("Jeff")

        ' Remove an entry that does not exist, but do not throw an exception.
        d.Remove("Max")

        ' Show the names (keys) of the people in the dictionary.
        Dim s As String

        For Each s In d.Keys
            Console.WriteLine(s)
        Next

        ' Show the ages (values) of the people in the dictionary.
        Dim age As Integer
        For Each age In d.Values
            Console.WriteLine(age)
        Next

    End Sub
End Class

' This code produces the following output.
'
' Number of elements in dictionary = 3
' Does dictionary contain 'Jeff'? True
' Jeff's age is 40
' Jeff is 40 years old.
' Kristin is 34 years old.
' Aidan is 1 years old.
' Kristin
' Aidan
' 34
' 1

설명

IDictionary 인터페이스는 키/값 쌍의 비일반 컬렉션에 대한 기본 인터페이스입니다. 이 인터페이스의 제네릭 버전은 를 참조하세요 System.Collections.Generic.IDictionary<TKey,TValue>.

각 요소는 개체에 저장된 키/값 쌍입니다 DictionaryEntry .

각 쌍에는 고유한 키가 있어야 합니다. 구현은 키가 null이 되도록 허용할지 여부에 따라 달라질 수 있습니다. 값은 null일 수 있으며 고유할 필요는 없습니다. IDictionary 인터페이스를 사용하면 포함된 키와 값을 열거할 수 있지만 특정 정렬 순서를 의미하지는 않습니다.

IDictionary 구현은 읽기 전용, 고정 크기, 가변 크기의 세 가지 범주로 구분됩니다. 읽기 전용 IDictionary 개체는 수정할 수 없습니다. 고정 크기 IDictionary 개체는 요소를 추가하거나 제거할 수 없지만 기존 요소를 수정할 수 있습니다. 가변 크기 IDictionary 개체를 사용하면 요소를 추가, 제거 및 수정할 수 있습니다.

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

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

문은 foreach 열거자 주위의 래퍼로, 컬렉션에서만 읽을 수 있지만 컬렉션에 쓸 수는 없습니다.

구현자 참고

구현 클래스에는 키를 비교할 수 있는 수단이 있어야 합니다.

속성

Count

ICollection에 포함된 요소 수를 가져옵니다.

(다음에서 상속됨 ICollection)
IsFixedSize

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

IsReadOnly

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

IsSynchronized

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

(다음에서 상속됨 ICollection)
Item[Object]

지정한 키를 가진 요소를 가져오거나 설정합니다.

Keys

ICollection 개체의 키를 포함하는 IDictionary 개체를 가져옵니다.

SyncRoot

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

(다음에서 상속됨 ICollection)
Values

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

메서드

Add(Object, Object)

제공된 키와 값을 가진 요소를 IDictionary 개체에 추가합니다.

Clear()

IDictionary 개체에서 요소를 모두 제거합니다.

Contains(Object)

IDictionary 개체에 지정한 키를 가진 요소가 포함되어 있는지 여부를 결정합니다.

CopyTo(Array, Int32)

특정 ICollection 인덱스부터 시작하여 Array의 요소를 Array에 복사합니다.

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

IDictionaryEnumerator 개체의 IDictionary 개체를 반환합니다.

Remove(Object)

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

확장 메서드

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보