In UiPath Studio development, there are times when you want to use an array of multiple variables in a single variable.
This article explains the difference between Array, List, and Dictionary arrays, and how to use them.
\Save during the sale period!/
Take a look at the UiPath course on the online learning service Udemy
*Free video available
Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch
This site was created by translating a blog created in Japanese into English using the DeepL translation.
Please forgive me if some of the English text is a little strange
- Difference between Array, List, and Dictionary
- Array
- List
- Procedure for creating a List variable
- Output each element of the List to the log.
- Adding elements to a List (Add To Collection)
- Remove an element from the List(Remove From Collection)
- Clear the elements in the List(Clear Collection)
- Replace an element in the List(Assign)
- Whether or not the element is in the List(Exists In Collection)
- Number of elements in the List(.Count)
- Dictionary
- Summary
Difference between Array, List, and Dictionary
Both Array and List can have multiple elements, and the elements are specified numerically.
The difference between Array and List is that Array does not allow you to add elements, while List allows you to add elements.
Dicitonary differs from Array and List in that the elements are specified by keys.
Number of elements | The value of the element | How to retrieve the data | |
Array | fixed | Changeable | numeric value specification |
List | variable | Changeable | numeric value specification |
Dictionary | variable | Changeable | Key designation |
Array
Array is an array with a fixed number of elements, changeable element values, and a numeric data retrieval method.
To create an Array variable
①To create an Array variable, click on “Array Of [T]” for the variable type.
②Select the variable T in the array, and click [OK].
③Make sure that the Array variable specified as the variable type is displayed.。
Output each element of an Array to the log
To log each element of an Array, you can use the “For Each” activity to extract each element, or you can specify the number of the Array variable.
The elements in the variable Array are iterated and numbered, and the values in the elements are output to the log.
・Text for each value in the process
{"apple","orange","banana"}
"repeat: "+item.ToString
"Numbering(0):"+arr(0)
"Numbering(1):"+arr(1)
"Numbering(2):"+arr(2)
・Assign Properties
・For Each Properties
・Variables
・Execution result Log
List
List is an array with a variable number of elements, changeable element values, and a numeric data retrieval method.
Procedure for creating a List variable
①Under Variable Types, click Browse for Types.
②”System.Collections.Generic.List” in the search window.
③Select [List<T>], select the variables to be specified in the array in the upper right corner, and click [OK].
④Make sure List<selected variable> is displayed for the variable type.
Output each element of the List to the log.
The log output for each element of the List can be done by extracting each element with the “For Each” activity, or by specifying the number of the List variable.
Repeats and numbers the elements in the variable List, and outputs the values in the elements to the log.
・Text for each value in the process
New List(of String) From{"apple", "orange","banana"}
"repeat: "+item.ToString
"Numbering(0):"+list(0)
"Numbering(1):"+list(1)
"Numbering(2):"+list(2)
・Assign Properties
・For Each Properties
・Variables
・Execution result Log
Adding elements to a List (Add To Collection)
To add an element to the list, use the “Add To Collection” activity.
“Add To Collection”は、Programming > Collection にあります。
Add an element to the variable List and output the value in the element to the log.
・Text for each value in the process
New List(of String) From{"apple", "orange","banana"}
"repeat: "+item.ToString
・Assign Properties
・Add To Collection Properties
・For Each Properties
・Variables
・Execution result Log
Remove an element from the List(Remove From Collection)
To remove an element from the list, use the “Remove From Collection” activity.
“Remove From Collection” is located in Programming > Collection.
Delete one element of the list and output the value in the element to the log.
・Assign Properties
・Remove From Collection Properties
・For Each Properties
・Variables
・Execution result Log
Clear the elements in the List(Clear Collection)
To clear all the elements of a list, use the “Clear Collection” activity.
“Clear Collection” is located in Programming > Collection.
Clear all elements of the list and output the values in the elements to the log.
・Assign Properites
・Clear Collection Properties
・For Each Properties
・Variables
・Execution result Log
Replace an element in the List(Assign)
To replace an element in the List, use the “Assign” activity.
“Assign” is located in Workflow > Control.
Replace one of the elements of the List with another value, and output the value in the element to the log.
・Assign list initialization Properties
・Assign Replace element 2 Properties
・For Each Properties
・Variables
・Execution result Log
Whether or not the element is in the List(Exists In Collection)
The “Exists In Collection” activity is used to check for the presence of a given element in a list.
“Exists In Collection” is located in Programming > Collection.
Checks for the presence of the specified element in the list and outputs the result to the log.
・Assign Properties
・Exists In Collection Properties
・Variables
・Execution result Log
Number of elements in the List(.Count)
For the number of elements in the List, use the Count of the List variable.
Count the number of elements in the list and output to the log.
・Text for each value in the process
New List(of String) From{"apple", "orange","banana"}
" list Number of elements: "+list.Count.ToString
・Assign Properties
・Variables
・Execution result Log
Dictionary
A Dictionary is an array with a variable number of elements, changeable element values, and a Key-specified way to retrieve data.
While Array and List specify elements by numbers, Dictionary specifies elements by “keys”.
Procedure for creating a Dictionary variable
①Under Variable types, click Browser for types.
②”System.Collections.Generic.Dictionary” in the search window.
③Select [Dictionary<TKey><TValue>], select the variable types of Key and Value in the upper right pull-down, and click [OK] button.
④Make sure [Dictionary<selected Key variable type><selected Value variable type>] is displayed.
Output each element of the Dictionary to the log
To log each element of the dictionary, you can either extract each element with a “For Each” activity or specify a List variable with a Key.
It repeats the elements in the variable Dictionary and outputs the values in the elements to the log by specifying Key.
・Text for each value in the process
New Dictionary(of String, Integer) From{{"apple", 100},{"orange", 200},{"banana", 300}}
"apple value: "+dic("apple").ToString
"orange value: "+dic("orange").ToString
"banana: "+dic("banana").ToString
"repeat: "+item+" "+dic(item).ToString
・Assign
・For Each
・Variables
・Execution result Log
Add an element to Dictionary(Assign)
To add elements to the dictionary, use the “Assign” activity.
“Assign” is located in Workflow > Control.
Add an element to the Dictionary and output the value in the element to the log.
・Text for each value in the process
New Dictionary(of String, Integer) From{{"apple", 100},{"orange", 200},{"banana", 300}}
item+":"+dic(item).ToString
・Assign dic initialization Properties
・For Each Properties
・Variables
・Execution result Log
Remove an element from a dictionary (InvokeMethod )
Use the [InvokeMethod] activity to delete an element from the Dictionary.
[InvokeMethod] is located in Programming > Excure.
Delete one element of the Dictionary and output the value in the element to the log.
・Assign Properties
・InvokeMethod Properties
・Value of the “Parameter” in the “Method Name”.
・For Each Properties
・Variables
・Execution result Log
Replace an element in a dictionary (Assign)
To replace an element in the Dictionary, use the “Assign” activity.
“Assign” is located in Workflow > Control.
Replace one of the elements of the Dictionary with another value, and output the value in the element to the log.
・Assign Initialization Properties
・Assign Replace Properties
・For Each Properties
・Variables
・Execution result Log
Number of elements in the Dictionary(.Count)
The number of elements in the Dictionary uses the Count of the Dictionary variable.
Counts the number of elements in the Dictionary and outputs it to the log.
・Assign Properties
・LogMessage
・Variavbles
・Execution result Log
Summary
- Array is an array with a fixed number of elements, changeable element values, and a numeric data retrieval method.
- List is an array with a variable number of elements, changeable element values, and a numeric data retrieval method.
- A Dictionary is an array with a variable number of elements, changeable element values, and a key-specified data retrieval method.
- List is easier to use than Array because the number of elements is variable.
- If you want to specify the key, use Dictionary.
\Save during the sale period!/
Take a look at the UiPath course on the online learning service Udemy
*Free video available
Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch
same category UiPath
Japanese IT engineer with a wide range of experience in system development, cloud building, and service planning. In this blog, I will share my know-how on UiPath and certification. profile detail / twitter:@fpen17