DictionaryEntry Struktur

Definition

Definiert ein Wörterbuchschlüssel-Wert-Paar, das festgelegt oder abgerufen werden kann.

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
Vererbung
DictionaryEntry
Attribute

Beispiele

Im folgenden Beispiel wird die Verwendung des Durchlaufens DictionaryEntry eines Hashtable Objekts veranschaulicht.

// 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

Hinweise

Die IDictionaryEnumerator.Entry Methode gibt eine Instanz dieses Typs zurück.

Von Bedeutung

Es wird nicht empfohlen, die DictionaryEntry Struktur für die neue Entwicklung zu verwenden. Stattdessen wird empfohlen, eine generische KeyValuePair<TKey,TValue> Struktur zusammen mit der Dictionary<TKey,TValue> Klasse zu verwenden. Weitere Informationen finden Sie unter "Nicht generische Sammlungen", die nicht auf GitHub verwendet werden sollten .

Die C# foreach-Anweisung und die Visual Basic For Each-Anweisung erfordern den Typ der einzelnen Elemente in der Auflistung. Da jedes Element ein IDictionary Schlüssel-Wert-Paar ist, ist der Elementtyp nicht der Typ des Schlüssels oder des Typs des Werts. Stattdessen lautet DictionaryEntryder Elementtyp . Beispiel:

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

Die foreach Anweisung ist ein Wrapper um den Enumerator, der nur das Lesen von , nicht schreiben in die Auflistung ermöglicht.

Konstruktoren

Name Beschreibung
DictionaryEntry(Object, Object)

Initialisiert eine Instanz des DictionaryEntry Typs mit dem angegebenen Schlüssel und Wert.

Eigenschaften

Name Beschreibung
Key

Dient zum Abrufen oder Festlegen des Schlüssels im Schlüssel-Wert-Paar.

Value

Dient zum Abrufen oder Festlegen des Werts im Schlüssel-Wert-Paar.

Methoden

Name Beschreibung
Deconstruct(Object, Object)

Deconstructs the current DictionaryEntry.

Gilt für:

Weitere Informationen