StringCollection.IList.Insert(Int32, Object) 方法


将元素插入 StringCollection 的指定索引处。Inserts an element into the StringCollection at the specified index.

 virtual void System.Collections.IList.Insert(int index, System::Object ^ value) = System::Collections::IList::Insert;
void IList.Insert (int index, object value);
abstract member System.Collections.IList.Insert : int * obj -> unit
override this.System.Collections.IList.Insert : int * obj -> unit
Sub Insert (index As Integer, value As Object) Implements IList.Insert



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


要插入的 ObjectThe Object to insert. 该值可以为 nullThe value can be null.



index 小于零。index is less than zero.

- 或 --or- index 大于 Countindex is greater than Count.

StringCollection 为只读。The StringCollection is read-only.

- 或 --or- StringCollection 具有固定的大小。The StringCollection has a fixed size.


如果 Count 已等于容量,则会 StringCollection 自动重新分配内部数组,并将现有元素复制到新数组,然后再添加新的元素。If Count already equals the capacity, the capacity of the StringCollection is increased by automatically reallocating the internal array, and the existing elements are copied to the new array before the new element is added.

如果 index 等于 Countvalue 则将添加到的末尾 StringCollectionIf index is equal to Count, value is added to the end of StringCollection.

在由连续的元素组成的集合(如列表)中,插入点下面的元素将下移以容纳新的元素。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.

此方法是 O (n) 操作,其中 nCountThis method is an O(n) operation, where n is Count.