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)
Step 2:
Drag “Assign” activities into the designer panel and add the following things to the above dictionary.
Name: Sharath
our_Dictionary(“Name”) = “Sharath”
Location: India
our_Dictionary(“Location”) = “India”
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.
Step 4:
Finally, run the project to display the items in the dictionary!!!
Click here to download the Source Code…
Hope it has helped you…