How To Add/Loop through Dictionary – In UiPath

During the programming, we might want to save some values as key and value pairs so that we use them later.

Dictionary is a generic collection which is generally used to store key/value pairs.

Declaring A Dictionary
My_Dictionary = new Dictionary(TKey,TValue)

Note:
TKey can be of Int,String….
TValue can be of Int,String…

Example

Implementation using UiPath :

Let’s develop a workflow where we will add two Key and Value pairs to the Dictionary and will display all the items available in the dictionary.

Step 1:
Drag “Assign” activity into the designer panel and define a declared dictionary with a “key” of string type and “value” of object type.

our_Dictionary = new Dictionary(Of String,Object)

UiPath Add Retrieve items from dictionary 1.png

Step 2:
Drag “Assign” activities into the designer panel and add the following things to the above dictionary.

Name: Sharath
our_Dictionary(“Name”) = “Sharath”

UiPath Add Retrieve items from dictionary 2

Location: India
our_Dictionary(“Location”) = “India”

UiPath Add Retrieve items from dictionary 3

Step 3:
Drag “For Each” activity into the designer panel and pass the above the dictionary to it.

Don’t forget to change the “TypeArgument” to
System.Collections.Generic.KeyValuePair<System.String, System.Object> in the properties window.

Use the “Message box” activity to display the key and value as we iterate the dictionary.

UiPath Add Retrieve items from dictionary 4.pngUiPath Add Retrieve items from dictionary 5.png

Step 4:
Finally, run the project to display the items in the dictionary!!!

UiPath Add Retrieve items from dictionary 6.PNG

Click here to download the Source Code…

Hope it has helped you…

Leave a Reply

%d bloggers like this: