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