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?
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.
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
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.
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?
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)
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.