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

@Boopathi

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

@Boopathi

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 @Boopathi

See image below for your reference.

cheers :smiley:

Happy learning :smiley:

1 Like

@Boopathi

We can do it. Check @pattyricarte post.

1 Like

Hi @Boopathi
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 @Boopathi

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

Thanks for your reply, Palaniyappan.
Guess I was not very clear with my query.
Thing is I have 250 fields of list declaration and initialization to be done, which I am currently, post declaration of the list, initializing it as {"", “”, “”, “”…}.
But this, though required once, needs to manually done for all such lists where the records are used inside of lists.
Is there a mechanism to simply define the list to hold X number of values, and not initialize every index with a value (in this case, empty strings); a way to declare it as aList = new List(Of String){250} or so and then use aList(indexvalue) in any order of index, and in a non-sequential way, to assign values using Assign activity.

Hope this clarifies the question.
Let me know if you require more information.

Thanks,
Ulhas S.

@shettyulhas7
are looking on something like this?
grafik

Perfect! Exactly what i was looking for!
Thanks Peter, Palaniyappan for your help here.

Ulhas S.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.