ToArray Method

Copies the elements of the ArrayList Object to a new array.

Synatx

Object.ToArray()

Arguments - Object: Required. Always the name of ArrayList object.

Returns

An array containing copies of the elements of the ArrayList object

Remarks

The following example illustrates the use of the ToArray method.

Example 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