DictionaryEntry Struktur
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Definiert ein wörterbuchbezogenes Schlü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
- Attribute
Beispiele
Im folgenden Beispiel wird die Verwendung DictionaryEntry des Iterierens durch ein Hashtable Objekt veranschaulicht.
// 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
Hinweise
Die IDictionaryEnumerator.Entry Methode gibt eine Instanz dieses Typs zurück.
Wichtig
Es wird nicht empfohlen, die DictionaryEntry
Struktur für 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 für GitHub verwendet werden sollten.
Die C# foreach-Anweisung und die Visual Basic For Each-Anweisung erfordern den Typ jedes Elements in der Auflistung. Da jedes Element IDictionary eines Schlüssel-Wert-Paars ein Schlüssel-/Wertpaar ist, ist der Elementtyp nicht der Typ des Schlüssels oder des Typs des Werts. Stattdessen ist DictionaryEntryder Elementtyp . Beispiel:
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 es nur ermöglicht, von der Sammlung aus zu lesen, nicht zu schreiben.
Konstruktoren
DictionaryEntry(Object, Object) |
Initialisiert eine Instanz des DictionaryEntry-Typs mit dem angegebenen Schlüssel und Wert. |
Eigenschaften
Key |
Ruft den Schlüssel im Schlüssel-Wert-Paar ab oder legt diesen fest. |
Value |
Ruft den Wert im Schlüssel-Wert-Paar ab oder legt diesen fest. |
Methoden
Deconstruct(Object, Object) |
Dekonstruiert die aktuelle DictionaryEntry-Struktur. |