DictionaryEntry 구조체

정의

설정하거나 검색할 수 있는 사전 키/값 쌍을 정의합니다.

public value class DictionaryEntry
public struct DictionaryEntry
[System.Serializable]
public struct DictionaryEntry
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct DictionaryEntry
type DictionaryEntry = struct
[<System.Serializable>]
type DictionaryEntry = struct
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type DictionaryEntry = struct
Public Structure DictionaryEntry
상속
DictionaryEntry
특성

예제

다음 예제에서는 를 사용하여 DictionaryEntry 개체를 반복하는 방법을 보여 줍니다 Hashtable .

// A simple example for the DictionaryEntry structure.
using namespace System;
using namespace System::Collections;

public ref class Example
{
public:
    static void Main()
    {
        // Create a new hash table.
        //
        Hashtable^ openWith = gcnew Hashtable();

        // Add some elements to the hash table. There are no
        // duplicate keys, but some of the values are duplicates.
        openWith->Add("txt", "notepad.exe");
        openWith->Add("bmp", "paint.exe");
        openWith->Add("dib", "paint.exe");
        openWith->Add("rtf", "wordpad.exe");

        // When you use foreach to enumerate hash table elements,
        // the elements are retrieved as DictionaryEntry objects.
        Console::WriteLine();
        for each (DictionaryEntry de in openWith)
        {
            Console::WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
        }
    }
};

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

/* This code example produces output similar to the following:

Key = rtf, Value = wordpad.exe
Key = txt, Value = notepad.exe
Key = dib, Value = paint.exe
Key = bmp, Value = paint.exe
 */
// A simple example for the DictionaryEntry structure.
using System;
using System.Collections;

class Example
{
    public static void Main()
    {
        // Create a new hash table.
        //
        Hashtable openWith = new Hashtable();

        // Add some elements to the hash table. There are no
        // duplicate keys, but some of the values are duplicates.
        openWith.Add("txt", "notepad.exe");
        openWith.Add("bmp", "paint.exe");
        openWith.Add("dib", "paint.exe");
        openWith.Add("rtf", "wordpad.exe");

        // When you use foreach to enumerate hash table elements,
        // the elements are retrieved as DictionaryEntry objects.
        Console.WriteLine();
        foreach (DictionaryEntry de in openWith)
        {
            Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
        }
    }
}

/* This code example produces output similar to the following:

Key = rtf, Value = wordpad.exe
Key = txt, Value = notepad.exe
Key = dib, Value = paint.exe
Key = bmp, Value = paint.exe
 */
'A simple example for the DictionaryEntry structure.
Imports System.Collections

Module Example

    Sub Main()

        ' Create a new hash table.
        '
        Dim openWith As New Hashtable()

        ' Add some elements to the hash table. There are no
        ' duplicate keys, but some of the values are duplicates.
        openWith.Add("txt", "notepad.exe")
        openWith.Add("bmp", "paint.exe")
        openWith.Add("dib", "paint.exe")
        openWith.Add("rtf", "wordpad.exe")

        ' When you use For Each to enumerate hash table elements,
        ' the elements are retrieved as DictionaryEntry objects.
        Console.WriteLine()
        For Each de As DictionaryEntry In openWith
            Console.WriteLine("Key = {0}, Value = {1}", _
                de.Key, de.Value)
        Next de

    End Sub

End Module

' This code example produces output similar to the following:
'
'Key = rtf, Value = wordpad.exe
'Key = txt, Value = notepad.exe
'Key = dib, Value = paint.exe
'Key = bmp, Value = paint.exe

설명

메서드는 IDictionaryEnumerator.Entry 이 형식의 인스턴스를 반환합니다.

중요

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

C# foreach 문과 Visual Basic For Each 문에는 컬렉션에 있는 각 요소의 형식이 필요합니다. 의 IDictionary 각 요소는 키/값 쌍이므로 요소 형식은 키의 형식이나 값의 형식이 아닙니다. 대신 요소 형식은 입니다 DictionaryEntry. 예를 들면 다음과 같습니다.

for each (DictionaryEntry de in openWith)
{
    Console::WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}
foreach (DictionaryEntry de in openWith)
{
    Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}
For Each de As DictionaryEntry In openWith
    Console.WriteLine("Key = {0}, Value = {1}", _
        de.Key, de.Value)
Next de

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

생성자

DictionaryEntry(Object, Object)

지정된 키와 값을 사용하여 DictionaryEntry 형식의 인스턴스를 초기화합니다.

속성

Key

키/값 쌍에서 키를 가져오거나 설정합니다.

Value

키/값 쌍에서 값을 가져오거나 설정합니다.

메서드

Deconstruct(Object, Object)

현재 DictionaryEntry를 분해합니다.

적용 대상

추가 정보