Represents a collection of key/value pairs that are accessible by the key or index.
Assembly: System (in System.dll)
Each element is a key/value pair stored in a DictionaryEntry object. A key cannot be a null reference (Nothing in Visual Basic), but a value can be.
The elements of an are not sorted in any way. collections allow access by both index as well as key.
The foreach statement of the C# language (For Each in Visual Basic) requires the type of each element in the collection. Since each element of the collection 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. The following code shows C# and Visual Basic syntax.
[Visual Basic, C#]
The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.
The following code example demonstrates the creation, population and modification of an collection, as well as two techniques to display the contents of the : one using the Keys and Values properties and the other creating an enumerator through the GetEnumerator method.
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
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.