Add 方法

将元素添加到 ArrayList 对象的末尾。

语法

Object.Add (Element)

参数:

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

  • Element必需。要添加到 ArrayList 末尾的元素

返回

在其中添加元素的 ArrayList 索引

注释

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

示例 1:

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

'Add Elements to the ArrayList Object
Dim Index
Index = Obj.Add(10)
'Output: 0
Index = Obj.Add(40)
'Output: 1
Index = Obj.Add(20)
'Output: 2
'Output: Obj contains 10, 40, 20

示例 2:

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

'Add Elements to the end of the ArrayList Object
Dim Index
Index = Obj.Add("Banana")
'Output: 0
Index = Obj.Add("Apple")
'Output: 1
Index = Obj.Add("Grapes")
'Output: 2
'Output: Obj contains "Banana", "Apple", "Grapes"