DictionaryEntry Struct
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Definieert een woordenlijstsleutel/waardepaar dat kan worden ingesteld of opgehaald.
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
- Overname
- Kenmerken
Voorbeelden
In het volgende voorbeeld ziet u het gebruik van het doorlopen van DictionaryEntry een Hashtable object.
// 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
Opmerkingen
De IDictionaryEnumerator.Entry methode retourneert een exemplaar van dit type.
Important
We raden u niet aan de DictionaryEntry structuur te gebruiken voor nieuwe ontwikkeling. In plaats daarvan raden we u aan een algemene KeyValuePair<TKey,TValue> structuur samen met de Dictionary<TKey,TValue> klas te gebruiken. Zie Aangenaamde verzamelingen niet worden gebruikt op GitHub voor meer informatie.
De instructie C# foreach en de instructie Visual Basic Voor elke instructie is het type van elk element in de verzameling vereist. Omdat elk element van het IDictionary element een sleutel/waardepaar is, is het elementtype niet het type van de sleutel of het type van de waarde. In plaats daarvan is DictionaryEntryhet elementtype . Voorbeeld:
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
De foreach instructie is een wrapper rond de enumerator, waarmee alleen kan worden gelezen van, niet schrijven naar, de verzameling.
Constructors
| Name | Description |
|---|---|
| DictionaryEntry(Object, Object) |
Initialiseert een exemplaar van het DictionaryEntry type met de opgegeven sleutel en waarde. |
Eigenschappen
| Name | Description |
|---|---|
| Key |
Hiermee wordt de sleutel opgehaald of ingesteld in het sleutel-/waardepaar. |
| Value |
Hiermee haalt u de waarde op in het sleutel-/waardepaar of stelt u deze in. |
Methoden
| Name | Description |
|---|---|
| Deconstruct(Object, Object) |
Hiermee wordt de huidige DictionaryEntrygedeconstrueerd. |