KeyedCollection(TKey, TItem).GetKeyForItem Method
When implemented in a derived class, extracts the key from the specified element.
Assembly: mscorlib (in mscorlib.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.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.