将 ArrayList 对象的元素复制到新数组中。
语法
Object.ToArray()
参数 - Object:必需。始终为 ArrayList 对象的名称。
返回
包含 ArrayList 对象元素副本的数组
注释
以下示例说明了 ToArray 方法的用法。
示例 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)
'Copies the elements of the ArrayList object to a new array
Dim ArrObj
ArrObj = Obj.ToArray()
'Display Elements from Array
For Each Element In ArrObj
'Operation based on requirement using each element of Array
Next
'Output: ArrObj contains 10, 40, 20, 30