DictionaryEntry DictionaryEntry DictionaryEntry DictionaryEntry Struct

Definizione

Consente di definire una coppia chiave/valore di dizionario che è possibile impostare o recuperare.Defines a dictionary key/value pair that can be set or retrieved.

public value class DictionaryEntry
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct DictionaryEntry
type DictionaryEntry = struct
Public Structure DictionaryEntry
Ereditarietà
DictionaryEntryDictionaryEntryDictionaryEntryDictionaryEntry
Attributi

Esempi

Nell'esempio seguente viene illustrato l'utilizzo di DictionaryEntry per scorrere un Hashtable oggetto.The following example demonstrates the use of DictionaryEntry to iterate through a Hashtable object.

// 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
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 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

Commenti

Il IDictionaryEnumerator.Entry metodo restituisce un'istanza di questo tipo.The IDictionaryEnumerator.Entry method returns an instance of this type.

Importante

Non è consigliabile usare il DictionaryEntry struttura per i nuovi sviluppi.We don't recommend that you use the DictionaryEntry structure for new development. È invece consigliabile usare un oggetto generico KeyValuePair<TKey,TValue> struttura lungo il Dictionary<TKey,TValue> classe.Instead, we recommend that you use a generic KeyValuePair<TKey,TValue> structure along with the Dictionary<TKey,TValue> class. Per altre informazioni, vedere raccolte Non generiche non devono essere usate su GitHub.For more information, see Non-generic collections shouldn't be used on GitHub.

Il C# foreach informativa e Visual Basic per ogni istruzione richiedono il tipo di ogni elemento nella raccolta.The C# foreach statement and the Visual Basic For Each statement require the type of each element in the collection. Poiché ogni elemento del IDictionary è una coppia chiave/valore, il tipo di elemento non è il tipo della chiave o il tipo del valore.Since each element of the IDictionary is a key/value pair, the element type is not the type of the key or the type of the value. Al contrario, il tipo di elemento è DictionaryEntry.Instead, the element type is DictionaryEntry. Ad esempio:For example:

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

Il foreach istruzione è un wrapper per l'enumeratore, che consente solo di leggere da, non la scrittura, la raccolta.The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

Costruttori

DictionaryEntry(Object, Object) DictionaryEntry(Object, Object) DictionaryEntry(Object, Object) DictionaryEntry(Object, Object)

Inizializza un'istanza del tipo DictionaryEntry con la chiave e il valore specificati.Initializes an instance of the DictionaryEntry type with the specified key and value.

Proprietà

Key Key Key Key

Ottiene o imposta la chiave nella coppia chiave/valore.Gets or sets the key in the key/value pair.

Value Value Value Value

Ottiene o imposta il valore nella coppia chiave/valore.Gets or sets the value in the key/value pair.

Metodi

Deconstruct(Object, Object) Deconstruct(Object, Object) Deconstruct(Object, Object) Deconstruct(Object, Object)

Si applica a

Vedi anche