KeyedCollection<TKey, TItem>.InsertItem Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Inserts an element into the KeyedCollection<TKey, TItem> at the specified index.
Namespace: System.Collections.ObjectModel
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Protected Overrides Sub InsertItem ( _
index As Integer, _
item As TItem _
)
protected override void InsertItem(
int index,
TItem item
)
Parameters
- index
Type: System.Int32
The zero-based index at which item should be inserted.
- item
Type: TItem
The object to insert.
Exceptions
Exception | Condition |
---|---|
ArgumentOutOfRangeException | index is less than 0. -or- index is greater than Count. |
Remarks
If index is equal to Count, item is added to the end of the KeyedCollection<TKey, TItem>.
Important Note: |
---|
This method overrides the protected Collection<T>.InsertItem(Int32, T) method. The two methods are not overloads, as the overload list page states. In fact, they have exactly the same signature, because the base class of KeyedCollection<TKey, TItem> (KeyedCollection(Of TKey, TItem) in Visual Basic, generic<TKey, TItem> ref class KeyedCollection in C++) is Collection<TItem>, where the generic type parameter TItem of KeyedCollection<TKey, TItem> is substituted for the generic type parameter T of the Collection<T> generic class. The documentation build tools do not resolve these signatures correctly. |
This method is an O(n) operation, where n is Count.
Notes for Implementers
Override this method to provide customized behavior for the Add and Insert methods, inherited from the Collection<T> generic class.
Call the base class implementation of this method to insert the item into the underlying collection and to update the lookup dictionary.
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
XNA Framework
Supported in: Xbox 360, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also