DictionaryEntry Estrutura
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Define um par chave/valor de dicionário que pode ser definido ou recuperado.
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
- Herança
- Atributos
Exemplos
O exemplo seguinte demonstra a utilização de DictionaryEntry para iterar através de um Hashtable objeto.
// 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
Observações
O IDictionaryEnumerator.Entry método devolve uma instância deste tipo.
Importante
Não recomendamos que utilize a DictionaryEntry estrutura para novos empreendimentos. Em vez disso, recomendamos que utilize uma estrutura genérica KeyValuePair<TKey,TValue> juntamente com a Dictionary<TKey,TValue> aula. Para mais informações, veja Não devem ser usadas coleções não genéricas em GitHub.
A instrução C# foreach e a sentença Visual Basic For Each requerem o tipo de cada elemento na coleção. Como cada elemento de é IDictionary um par chave/valor, o tipo de elemento não é o tipo da chave nem o tipo do valor. Em vez disso, o tipo de elemento é DictionaryEntry. Por exemplo:
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
A foreach declaração é um wrapper em torno do enumerador, que só permite ler a partir da coleção, não escrever para.
Construtores
| Name | Description |
|---|---|
| DictionaryEntry(Object, Object) |
Inicializa uma instância do DictionaryEntry tipo com a chave e valor especificados. |
Propriedades
| Name | Description |
|---|---|
| Key |
Obtém ou define a chave no par chave/valor. |
| Value |
Obtém ou define o valor no par chave/valor. |
Métodos
| Name | Description |
|---|---|
| Deconstruct(Object, Object) |
Desconstrói a corrente DictionaryEntry. |