Initialization of List like array

Hi Team,

Just a doubt. We initialize array like {“One”,“Two”} and can we not initialize list in the same way(It is throwing error) instead of adding them using add to collection or invoke method activity. Could someone clarify this as both are just like a container?

Thanks,
Ula

1 Like

@Ula

We can Initialize List also.

Create one list variable and Initialize like below.

Ex: New List(Of String)({“Uipath Studio”, “Uipath Robot”, "Orchestrator "})

Thank you @lakshman but can we not do it using assign activity. If I give values using assign activity then it is showing error.

1 Like

@Ula

It’s not in Assign activity and Initialize List at the time of creation under Variables panel.

Hi @lakshman Sorry for any misunderstanding. I am aware that we can initialize the list from the variables panel but not able to do so using assign activity. I am able to assign the values to MyArray variable but not MyList variable. I know we can add items to list using add to collection or invoke method but just want to know why we are not able to initialize values to list using assign activity.

image

Hi, did you initialize the list before using it in assign activity? List is different from array, it needs to be initialized before you put in anything into it.

Hi @Ula

See image below for your reference.

cheers :smiley:

Happy learning :smiley:

1 Like

@Ula

We can do it. Check @pattyricarte post.

1 Like

Hi @Ula
you can initialize List by using the methods which Posted by @lakshman and @pattyricarte and if you want to add elements in the list dynamically then you can use Add to Collection activity.

1 Like

To initialise a list with values
New List(of string) from {“value1”,”value2”}

We can either add value by this way in variable panel along default value column itself or in a assign activity
Both would work for sure

Cheers @Ula

Hi Palani.
Anyway we can initialize this List variable if I don’t know or yet to assign values to List indexes, but already know the length of the list (don’t want to use arrays).
For now, we are defining the list and initializing it using while loop, assigning default values (empty strings) using Add to collection activity for it’s known length.
Need this information as the value assignments to the list is not sequential for it’s indexes.

Anyway, I can avoid the while and add to collection activity and instead default values for all index values of this list, in say, just one line/assign/variable default fashion?

Thanks,
Ulhas S.

1 Like

Hi
Welcome to uipath community
Ofcourse We can, if we know the value with which we need to initialise the list variable and the number of elements, then we can do that in a simple way as mentioned with assign or in variable panel
Even if we want to add values in more numbers dey we have another list variable and if we want to merge that with our current one then we can Concatenate them with listvariable1.Concat(listvariable2)

Cheers @shettyulhas7