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.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8