Export (0) Print
Expand All

DictionaryEntry Structure

Defines a dictionary key/value pair that can be set or retrieved.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
public value class DictionaryEntry

The DictionaryEntry type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsDictionaryEntryInitializes an instance of the DictionaryEntry type with the specified key and value.
Top

  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsKeyGets or sets the key in the key/value pair.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsValueGets or sets the value in the key/value pair.
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEqualsIndicates whether this instance and a specified object are equal. (Inherited from ValueType.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeReturns the hash code for this instance. (Inherited from ValueType.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkToStringReturns the fully qualified type name of this instance. (Inherited from ValueType.)

In XNA Framework 3.0, this member is inherited from Object::ToString().
Top

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:

for each (DictionaryEntry de in openWith)
{
    Console::WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
}

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft