从 ArrayList 对象获取或设置指定索引处的元素。
语法
Object.Item(Index)
参数:
Object:必需。始终为 ArrayList 对象的名称。
Index:必需。要获取的元素的基于零的索引。
返回
返回索引中的元素。
注释
以下示例说明了 Item 方法的用法。
示例 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)
'Output: Obj contains 10, 40, 20
'Gets the Element from the ArrayList Object
Dim Element
Index = 2
If Index < Obj.Count() Then
Element = Obj.Item(Index)
'Output: 20
End If
'Set the Element in the ArrayList Object
Index = 1
If Index < Obj.Count() Then
Obj.Item(Index) = 15
End If
'Output: Obj contains 10, 15, 20