Collection<(Of <(T>)>).Insert Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

Syntax

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 nullNothingnullptra null reference (Nothing in Visual Basic) for reference types.

Implements

IList<(Of <(T>)>)..::.Insert(Int32, T)

Exceptions

Exception Condition
ArgumentOutOfRangeException

index is less than zero.

-or-

index is greater than Count.

Remarks

Collection<(Of <(T>)>) accepts nullNothingnullptra 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<(Of <(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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

Collection<(Of <(T>)>) Class

System.Collections.ObjectModel Namespace

Add

Remove