Freigeben über


DictionaryEntry-Struktur

Definiert ein Schlüssel-Wert-Paar für ein Wörterbuch, das festgelegt oder abgerufen werden kann.

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Structure DictionaryEntry
'Usage
Dim instance As DictionaryEntry
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public struct DictionaryEntry
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public value class DictionaryEntry
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DictionaryEntry extends ValueType
JScript unterstützt die Verwendung von Strukturen, aber nicht die Deklaration von neuen Strukturen.

Hinweise

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

Für die foreach-Anweisung in C# (for each in Visual C++, For Each in Visual Basic) ist der Typ jedes Elements in der Auflistung erforderlich. Da jedes Element des IDictionary ein Schlüssel-Wert-Paar ist, ist der Elementtyp nicht der Typ des Schlüssels oder Werts. Stattdessen ist der Elementtyp DictionaryEntry. Beispiel:

foreach (DictionaryEntry de in myHashtable) {...}
for each (DictionaryEntry^ de in myHashtable) {...}
For Each de As DictionaryEntry In myHashtable
   ...
Next de

Die foreach-Anweisung ist ein Wrapper um den Enumerator, der nur das Lesen aus der Auflistung aber nicht das Schreiben in diese zulässt.

Beispiel

Im folgenden Beispiel wird die Verwendung von DictionaryEntry zum Durchlaufen eines Hashtable-Objekts veranschaulicht.

'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 KeyValuePair 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 = winword.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 KeyValuePair 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
 */

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

DictionaryEntry-Member
System.Collections-Namespace
IDictionary
IDictionaryEnumerator
System.Collections.Generic.KeyValuePair