How To Define Dictionary, Add Items To Dictionary and Access Items From Dictionary – In UiPath

What is a Dictionary?

In general, a Dictionary is a collection of words and their Meanings/Definitions.

In the same Dictionary in any programming language is a collection of Keys and Values, where “Key” is equivalent to Words and “Value” is equivalent to Meanings/Definitions.

The Dictionary<TKey, TValue>  is a generic collection class available in the System.Collection.Generics namespace. Here “TKey” denotes the type of key and “TValue” is the type of TValue.

Example

Implementation using UiPath :

Let us implement a workflow to achieve the below functionalities

Major Steps That We Will Implement:

1. Defining a Dictionary
2. Adding items to the Dictionary
3. Accessing items from the Dictionary

Step 1:
Drag “Assign” activity into the designer panel and define the dictionary.

my_Dictionary = new Dictionary(Of String, String)
Here my_Dictionary is of System.Collection.Generics.Dictionary<String, String> type

Defining a Dictionary 1.png

Step 2:
Drag “Invoke Method” activity into the designer panel to add items to the Dictionary.

Example:
Key: INDIA
Value: New Delhi

Adding Items to Dictionary 2Defining a Dictionary 2

Step 3:
Another way of adding items Dictionary is by using Microsoft.Activities.Extensions package.

Drag “Add to dictionary” activity into the designer panel to add items to the Dictionary.

Example:
Key: USA
Value: Washington, D.C

Adding Items to Dictionary 3.PNG

Step 4:
Drag “Message Box” activity to display the first added Key and Value pair
i.e.  Find the Value of the Key “INDIA”

Accessing Dictionary 1.PNG

Step 5:
Drag “Message Box” activity to display the second added Key and Value pair.
i.e.  Find the Value of the Key “USA”

Accessing Dictionary 2.PNG

Step 6:
Finally, execute the workflow 🙂

Click here to download the Source Code…

Hope it has helped you…

Leave a Reply

%d bloggers like this: