DictionaryEntry Struktúra
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Meghatároz egy szótárkulcsot/értékpárt, amely beállítható vagy lekérhető.
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
- Öröklődés
- Attribútumok
Példák
Az alábbi példa az objektumon keresztüli DictionaryEntryHashtable iterálás használatát mutatja be.
// 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
Megjegyzések
A IDictionaryEnumerator.Entry metódus egy ilyen típusú példányt ad vissza.
Important
Nem javasoljuk, hogy a struktúrát DictionaryEntry új fejlesztéshez használja. Ehelyett azt javasoljuk, hogy az osztály mellett általános KeyValuePair<TKey,TValue> struktúrát Dictionary<TKey,TValue> is használjon. További információ: Non-generic gyűjtemények nem használhatók GitHub.
A C# foreach utasítás és a Visual Basic Minden utasításhoz a gyűjtemény egyes elemeinek típusa szükséges. Mivel a IDictionary kulcs minden eleme kulcs/érték pár, az elem típusa nem a kulcs típusa vagy az érték típusa. Ehelyett az elem típusa .DictionaryEntry Például:
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
Az foreach utasítás egy burkoló az enumerátor körül, amely csak a gyűjteményből való olvasást teszi lehetővé, nem pedig a gyűjteménybe való írást.
Konstruktorok
| Name | Description |
|---|---|
| DictionaryEntry(Object, Object) |
Inicializálja a DictionaryEntry típus egy példányát a megadott kulccsal és értékkel. |
Tulajdonságok
| Name | Description |
|---|---|
| Key |
Lekéri vagy beállítja a kulcsot a kulcs/érték párban. |
| Value |
Lekéri vagy beállítja az értéket a kulcs/érték párban. |
Metódusok
| Name | Description |
|---|---|
| Deconstruct(Object, Object) |
Az aktuális DictionaryEntryállapot dekonstruálása . |