System.Collections.Specialized.OrderedDictionary Class

Represents a collection of key/value pairs that are accessible by the key or index.

See Also: OrderedDictionary Members

Syntax

public class OrderedDictionary : IDictionary, IOrderedDictionary, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable

Remarks

Each element is a key/value pair stored in a DictionaryEntry object. A key cannot be null, but a value can be.

The elements of an System.Collections.Specialized.OrderedDictionary are not sorted by the key, unlike the elements of a SortedDictionary`2 class. You can access elements either by the key or by the index.

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 System.Collections.Specialized.OrderedDictionary 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#, Visual Basic and C++ syntax.

code reference: System.Collections.Specialized.OrderedDictionary1#06

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

Requirements

Namespace: System.Collections.Specialized
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0