DictionaryEntry DictionaryEntry DictionaryEntry DictionaryEntry Struct

Definition

Definiert ein Schlüssel-Wert-Paar für ein Wörterbuch, das festgelegt oder abgerufen werden kann.Defines a dictionary key/value pair that can be set or retrieved.

public value class DictionaryEntry
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct DictionaryEntry
type DictionaryEntry = struct
Public Structure DictionaryEntry
Vererbung
DictionaryEntryDictionaryEntryDictionaryEntryDictionaryEntry
Attribute

Beispiele

Das folgende Beispiel zeigt die Verwendung von DictionaryEntry zum iterieren durch eine Hashtable Objekt.The following example demonstrates the use of DictionaryEntry to iterate through a Hashtable object.

// 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
Imports System.Collections
Imports Microsoft.VisualBasic

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.The IDictionaryEnumerator.Entry method returns an instance of this type.

Wichtig

Es wird nicht empfohlen, dass Sie verwenden die DictionaryEntry Struktur für die neue Entwicklung.We don't recommend that you use the DictionaryEntry structure for new development. Stattdessen empfehlen wir die Verwendung eines generisches KeyValuePair<TKey,TValue> Struktur zusammen mit den Dictionary<TKey,TValue> Klasse.Instead, we recommend that you use a generic KeyValuePair<TKey,TValue> structure along with the Dictionary<TKey,TValue> class. Weitere Informationen finden Sie unter nicht generische Auflistungen nicht verwendet werden sollten auf GitHub.For more information, see Non-generic collections shouldn't be used on GitHub.

Die C# Foreach -Anweisung und die Visual Basic für jede -Anweisung erforderlich, den Typ jedes Elements in der Auflistung.The C# foreach statement and the Visual Basic For Each statement require the type of each element in the collection. Da jedes Element von der IDictionary Schlüssel/Wert-Paar, ist der Elementtyp ist nicht der Typ des Schlüssels oder den Typ des Werts.Since each element of the IDictionary is a key/value pair, the element type is not the type of the key or the type of the value. Stattdessen ist der Typ des Elements DictionaryEntry.Instead, the element type is DictionaryEntry. Beispiel:For example:

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

Die foreach Anweisung ist ein Wrapper um den Enumerator, der nur das Lesen aus nicht das Schreiben in die Auflistung zulässt.The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

Konstruktoren

DictionaryEntry(Object, Object) DictionaryEntry(Object, Object) DictionaryEntry(Object, Object) DictionaryEntry(Object, Object)

Initialisiert eine Instanz des DictionaryEntry-Typs mit dem angegebenen Schlüssel und Wert.Initializes an instance of the DictionaryEntry type with the specified key and value.

Eigenschaften

Key Key Key Key

Ruft den Schlüssel im Schlüssel-Wert-Paar ab oder legt diesen fest.Gets or sets the key in the key/value pair.

Value Value Value Value

Ruft den Wert im Schlüssel-Wert-Paar ab oder legt diesen fest.Gets or sets the value in the key/value pair.

Methoden

Deconstruct(Object, Object) Deconstruct(Object, Object) Deconstruct(Object, Object) Deconstruct(Object, Object)

Gilt für:

Siehe auch