RemoveAt 方法

删除 ArrayList 对象的指定索引处的元素。

语法

Object.RemoveAt(Index)

参数:

  • Object必需。始终为 ArrayList 对象的名称。

  • Index必需。要删除的元素的基于零的索引。

注释

以下示例说明了 RemoveAt 方法的用法。

示例 1:

'Create ArrayList Object
Dim Obj
Set Obj = CreateObject("System.Collections.ArrayList")

'Add Elements to the end of ArrayList Object
Dim Index
Index = Obj.Add(10)
Index = Obj.Add(40)
Index = Obj.Add(20)
Index = Obj.Add(30)


'Remove Element from the ArrayList Object
Index = 3
If index < Obj.Count() Then
Obj.RemoveAt(Index)
End If

'Display ArrayList Elements after Remove
For Each Element In Obj
'Operation based on requirement with the Element 
Next
'Output: Obj contains 10, 40, 20