KeyedCollection(TKey, TItem).GetKeyForItem Method
When implemented in a derived class, extracts the key from the specified element.
Assemblies: mscorlib (in mscorlib.dll)
System.ObjectModel (in System.ObjectModel.dll)
If the key in the lookup dictionary is different from the key that is embedded in item, you cannot access item by using the key returned by .
You can implement this method to return a null reference (Nothing in Visual Basic) for a collection that contains items without keys, in which case the items can be accessed only by their index. This method is an O(1) operation.
Notes for Implementers
You must override this method to provide the dictionary with a way to extract keys from items in the dictionary.
This method is called internally. It is not necessary for it to be public.
This code example shows the minimum code necessary to derive a collection class from KeyedCollection(TKey, TItem): overriding the method and providing a public constructor that delegates to a base class constructor. The code example also demonstrates many of the properties and methods inherited from KeyedCollection(TKey, TItem) and Collection(T) classes.
The SimpleOrder class is a very simple requisition list that contains OrderItem objects, each of which represents a line item in the order. The key of OrderItem is immutable, an important consideration for classes that derive from KeyedCollection(TKey, TItem). For a code example that uses mutable keys, see ChangeItemKey.
.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