Condividi tramite


KeyedCollection<TKey, TItem>.SetItem Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Replaces the item at the specified index with the specified item.

Namespace:  System.Collections.ObjectModel
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Protected Overrides Sub SetItem ( _
    index As Integer, _
    item As TItem _
)
protected override void SetItem(
    int index,
    TItem item
)

Parameters

  • index
    Type: System.Int32
    The zero-based index of the item to be replaced.
  • item
    Type: TItem
    The new item.

Remarks

The lookup dictionary is updated accordingly. That is, the key of the item that is being replaced is removed from the lookup dictionary, and the key of the new item is added.

Important noteImportant Note:

This method overrides the protected Collection<T>.SetItem(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(1) operation.

Notes for Implementers

Override this method to provide customized behavior for setting the Item property inherited from the Collection<T> generic class.

NoteNote:

This method does not affect the behavior of the KeyedCollection<TKey, TItem>.Item property, which is read-only.

Call the base class implementation of this method to set the item in 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.