Freigeben über


Collection<T>.Insert Method

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

Inserts an element into the Collection<T> at the specified index.

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

Syntax

'Declaration
Public Sub Insert ( _
    index As Integer, _
    item As T _
)
public void Insert(
    int index,
    T item
)

Parameters

  • index
    Type: System.Int32
    The zero-based index at which item should be inserted.
  • item
    Type: T
    The object to insert. The value can be nulla null reference (Nothing in Visual Basic) for reference types.

Implements

IList<T>.Insert(Int32, T)

Exceptions

Exception Condition
ArgumentOutOfRangeException

index is less than zero.

-or-

index is greater than Count.

Remarks

Collection<T> accepts nulla null reference (Nothing in Visual Basic) as a valid value for reference types and allows duplicate elements.

If index is equal to Count, item is added to the end of Collection<T>.

This method is an O(n) operation, where n is Count.

Notes to Inheritors

Derived classes can override InsertItem to change the behavior of this method.

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.