Define un par de clave y valor de diccionario que se puede establecer o recuperar.
Espacio de nombres: System.Collections
Ensamblado: mscorlib (en mscorlib.dll)
Visual Basic (Declaración)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Structure DictionaryEntry
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 admite el uso de estructuras, pero no admite la declaración de estructuras nuevas.
El método IDictionaryEnumerator.Entry devuelve una instancia de este tipo.
La instrucción foreach del lenguaje C# (for each en Visual C++, For Each en Visual Basic) requiere el tipo de cada elemento de la colección. Como los elementos de IDictionary son pares de clave y valor, el tipo del elemento no se corresponde con el tipo de la clave ni con el del valor. En su lugar, el tipo del elemento es DictionaryEntry. Por ejemplo:
foreach (DictionaryEntry de in myHashtable) {...}
for each (DictionaryEntry^ de in myHashtable) {...}
For Each de As DictionaryEntry In myHashtable
...
Next de
La instrucción foreach es un contenedor del enumerador, que sólo permite la lectura pero no la escritura en la colección.
En el ejemplo siguiente se muestra el uso de DictionaryEntry para recorrer en iteración un objeto Hashtable.
'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
*/
Seguridad para subprocesos
Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition
.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.
.NET Framework
Compatible con: 2.0, 1.1, 1.0
.NET Compact Framework
Compatible con: 2.0, 1.0