DictionaryEntry Structure
Defines a dictionary key/value pair that can be set or retrieved.
Assembly: mscorlib (in mscorlib.dll)
The IDictionaryEnumerator.Entry method returns an instance of this type.
The foreach statement of the C# language (for each in Visual C++, For Each in Visual Basic) requires the type of each element in the collection. 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. Instead, the element type is DictionaryEntry. For example:
The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.
The following example demonstrates the use of DictionaryEntry to iterate through a Hashtable object.
'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 = wordpad.exe 'Key = txt, Value = notepad.exe 'Key = dib, Value = paint.exe 'Key = bmp, Value = paint.exe
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.