Perform an activity for each array element

I’m using C# in my project and need some help using string arrays.

What I want to do is declare a string array, and then for each element in that array, perform a set of actions. I’ve never used arrays before in UiPath. I’ve managed to set the Data Type of the variable to ‘String’, but I haven’t yet populated it. And I don’t know what to do next. When I do populate the array, do I use curly or square brackets? How do I progress through the array when performing the actions, do I use a ‘For Each’ activity?

Any help would be gratefully received!

Thanks!

I hope you’ve created an array variable type String[] to populate it or to initialize it use Assign Activity and in save to field use you variable name and in values use new string[] { "Apple", "Banana", "Mango" } then use for each activity and pass the variable into the In field and go to properties set the type Argument as String then use the Write line activity or Message Box activity and pass currentItem to see the output.

Cheers

@paulparkes,

Declare the variable as Array of [T] on next screen select String

It should look like this.

Populating data in the array:

new string[] {"Mumbai", "Delhi", "Pune"}

Iterating through array:
Use For Each activity

Properties:

Full Workflow:

Output:

1 Like

Thank you SO much!!! It worked perfectly!! :smiley:

1 Like

@paulparkes,

Glad to hear that. Kindly close the thread by marking my answer as solution so it will be helpful to other members as well.

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