IDictionary Interface

IDictionary Interface

Represents a collection of key-and-value pairs.

For a list of all members of this type, see IDictionary Members.

[Visual Basic]
Public Interface IDictionary
   Inherits ICollection, IEnumerable
public interface IDictionary : ICollection, IEnumerable
public __gc __interface IDictionary : public ICollection,
public interface IDictionary implements ICollection, IEnumerable

Classes that Implement IDictionary

Class Description
BaseChannelObjectWithProperties Provides a base implementation of a channel object that wants to provide a dictionary interface to its properties.
DictionaryBase Provides the abstract (MustInherit in Visual Basic) base class for a strongly typed collection of key-and-value pairs.
ListDictionary Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.
PropertyCollection Contains the properties of a DirectoryEntry.
PropertyDescriptorCollection Represents a collection of PropertyDescriptor objects.
StateBag Manages the view state of ASP.NET server controls, including pages. This class cannot be inherited.


The IDictionary class is the base interface for collections of key-and-value pairs.

Each element is a key-and-value pair stored in a DictionaryEntry object.

Each association must have a unique key that is not a null reference (Nothing in Visual Basic), but the value of an association can be any object reference, including a null reference (Nothing). The IDictionary interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order.

IDictionary implementations fall into three categories: read-only, fixed-size, variable-size. A read-only IDictionary cannot be modified. A fixed-size IDictionary does not allow the addition or removal of elements, but it allows the modification of existing elements. A variable-size IDictionary allows the addition, removal and modification of elements.

[Visual Basic, C#] 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 IDictionary is a key-and-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:

foreach (DictionaryEntry myDE in myHashtable) {...}
[Visual Basic] 
Dim myDE As DictionaryEntry
For Each myDE In myHashtable
Next myDE

[Visual Basic, C#] The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.


Namespace: System.Collections


Assembly: Mscorlib (in Mscorlib.dll)

See Also

IDictionary Members | System.Collections Namespace | Hashtable

© 2016 Microsoft