KeyedCollection<'TKey, 'TItem>.Dictionary Property
Gets the lookup dictionary of the KeyedCollection<'TKey, 'TItem>.
Assembly: mscorlib (in mscorlib.dll)
By default, the KeyedCollection<'TKey, 'TItem> includes a lookup dictionary that is created when the first item is added. When an item is added to the KeyedCollection<'TKey, 'TItem>, the item's key is extracted once and saved in the lookup dictionary for faster searches. This behavior can be overridden by using the KeyedCollection<'TKey, 'TItem>(IEqualityComparer<'TKey>, Int32) constructor and specifying a dictionary creation threshold.
Retrieving the value of this property is an O(1) operation.
The following code example shows how to override the protected ChangeItemKey method to support mutable keys, and how to override the protected InsertItem, RemoveItem, ClearItems, and SetItem methods to maintain the integrity of the keys and the collection.
The code example creates the MutableKeys collection, which derives from KeyedCollection<'TKey, 'TItem>, and the MutableKey class. The MutableKey class has a settable Key property. When a new key is assigned to the property, the property setter calls the internal (Friend in Visual Basic) ChangeKey method of the collection to test whether the new key would conflict with an existing key. If so, an exception is thrown and the property value is not changed.
In order to maintain the connection between a MutableKey object and the MutableKeys collection and to prevent an object from being inserted into two collections, the MutableKey class has an internal (Friend in Visual Basic) Collection field. This field is maintained by the protected methods that provide custom behavior for adding and removing items from the collection, such as the InsertItem method. The field is set when the item is added to a collection and cleared when the item is removed.
Available since 8
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1