IList<T>.Insert(Int32, T) 方法

定义

IList<T> 中的指定索引处插入一个项。Inserts an item to the IList<T> at the specified index.

public:
 void Insert(int index, T item);
public void Insert (int index, T item);
abstract member Insert : int * 'T -> unit
Public Sub Insert (index As Integer, item As T)

参数

index
Int32

应插入 item 的从零开始的索引。The zero-based index at which item should be inserted.

item
T

要插入到 IList<T> 中的对象。The object to insert into the IList<T>.

异常

index 不是 IList<T> 中的有效索引。index is not a valid index in the IList<T>.

IList<T> 为只读。The IList<T> is read-only.

注解

如果 index 等于 IList<T> 中的项数,则将 item 追加到列表。If index equals the number of items in the IList<T>, then item is appended to the list.

在由连续的元素组成的集合(如列表)中,插入点下面的元素将下移以容纳新的元素。In collections of contiguous elements, such as lists, the elements that follow the insertion point move down to accommodate the new element. 如果集合具有索引,则移动的元素的索引也将更新。If the collection is indexed, the indexes of the elements that are moved are also updated. 此行为不适用于元素按概念划分为不同存储桶的集合,如哈希表。This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hash table.

适用于

另请参阅