將 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