System.DictionaryEntry

Overview

The System.DictionaryEntry structure represents a dictionary entry (a key/value pair) in a non-generic dictionary.

It is commonly used with collections that implement IDictionary and when iterating through a dictionary using IDictionaryEnumerator.

Syntax

public struct DictionaryEntry
{
    public DictionaryEntry(object key, object value);
    public object Key { get; set; }
    public object Value { get; set; }
}

Properties

Key
Value

Gets or sets the key of the DictionaryEntry.

Typeobject
Accesspublic
RemarksThe key must be unique within the collection that contains the entry.

Gets or sets the value of the DictionaryEntry.

Typeobject
Accesspublic
RemarksThe value can be any object, including null.

Remarks

DictionaryEntry is a value type. When used in collections that store objects, boxing and unboxing may occur, which can affect performance.

For new development, consider using the generic KeyValuePair<TKey,TValue> structure instead.

Examples

The following example demonstrates iterating through a non‑generic Hashtable and accessing each DictionaryEntry:

using System;
using System.Collections;

class Program
{
    static void Main()
    {
        Hashtable table = new Hashtable();
        table["Apple"] = "Red";
        table["Banana"] = "Yellow";

        foreach (DictionaryEntry entry in table)
        {
            Console.WriteLine($"Key = {entry.Key}, Value = {entry.Value}");
        }
    }
}

See also