This documentation is archived and is not being maintained.

ListDictionary Class

Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.

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

public class ListDictionary implements IDictionary, ICollection, IEnumerable

This is a simple implementation of IDictionary using a singly linked list. It is smaller and faster than a Hashtable if the number of elements is 10 or less. This should not be used if performance is important for large numbers of elements.

Items in a ListDictionary are not in any guaranteed order; code should not depend on the current order. The ListDictionary is implemented for fast keyed retrieval; the actual internal order of items is implementation-dependent and could change in future versions of the product.

Members, such as Item, Add, Remove, and Contains are O(n) operations, where n is Count.

A key cannot be a null reference (Nothing in Visual Basic), but a value can.

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 ListDictionary 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:

No code example is currently available or this language may not be supported.

The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.

The following code example demonstrates several of the properties and methods of ListDictionary.

No code example is currently available or this language may not be supported.

System.Object
  System.Collections.Specialized.ListDictionary

Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

This implementation does not provide a synchronized (thread safe) wrapper for a ListDictionary, but derived classes can create their own synchronized versions of the ListDictionary using the SyncRoot property.

Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

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.

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show: