ListDictionary Class
Implements IDictionary using a singly linked list. Recommended for collections that typically include fewer than 10 items.
Assembly: System (in System.dll)
| Name | Description | |
|---|---|---|
![]() | ListDictionary() | Creates an empty ListDictionary using the default comparer. |
![]() | ListDictionary(IComparer) | Creates an empty ListDictionary using the specified comparer. |
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of key/value pairs contained in the ListDictionary. |
![]() | IsFixedSize | Gets a value indicating whether the ListDictionary has a fixed size. |
![]() | IsReadOnly | Gets a value indicating whether the ListDictionary is read-only. |
![]() | IsSynchronized | Gets a value indicating whether the ListDictionary is synchronized (thread safe). |
![]() | Item(Object) | Gets or sets the value associated with the specified key. |
![]() | Keys | Gets an ICollection containing the keys in the ListDictionary. |
![]() | SyncRoot | Gets an object that can be used to synchronize access to the ListDictionary. |
![]() | Values | Gets an ICollection containing the values in the ListDictionary. |
| Name | Description | |
|---|---|---|
![]() | Add(Object, Object) | Adds an entry with the specified key and value into the ListDictionary. |
![]() | Clear() | Removes all entries from the ListDictionary. |
![]() | Contains(Object) | Determines whether the ListDictionary contains a specific key. |
![]() | CopyTo(Array, Int32) | Copies the ListDictionary entries to a one-dimensional Array instance at the specified index. |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetEnumerator() | Returns an IDictionaryEnumerator that iterates through the ListDictionary. |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | MemberwiseClone() | |
![]() | Remove(Object) | Removes the entry with the specified key from the ListDictionary. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IEnumerable.GetEnumerator() | Returns an IEnumerator that iterates through the ListDictionary. |
| Name | Description | |
|---|---|---|
![]() | AsParallel() | Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.) |
![]() | AsQueryable() | Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.) |
![]() | Cast<'TResult>() | Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.) |
![]() | OfType<'TResult>() | Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.) |
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 null, but a value can.
The foreach statement of the C# language (for each in Visual Basic) returns an object of the type of the elements 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:
The foreach statement is a wrapper around the enumerator, which only allows reading from, not writing to, the collection.
Available since 10
.NET Framework
Available since 1.1
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.




