How to create an array of unknown length in UiPath?

I am creating an array of string and have to add selective items (out of total items) in it. I know the count of total items but not the exact items to be added in array. Taking size as count of total items would obviously leave empty elements in array which is not required. On searching code, I found
Initial declaration: Dim stArray() As Integer
Resizing: ReDim stArray(1)
To keep the existing items in the Array: ReDim Preserve stArray(2)

However, on adding assign activity ReDim stArray(1) is throwing an error.
Please suggest how could I add array of unknown length in UiPath.


It’s better to use a List instead of an Array, if the size is not known. Makes all the hassle with resizing be handled internally by it.
Your use case is actually the main reason why a List type exists - to be able to have an Array-like collection that would scale dynamically.


about lists & arrays