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