How to access the key or value of a dictionary based on index?

Would like to print the key of a dictionary in a message box.

Would like to print the value of a dictionary in a message box.

@Aishwarya_Maggi
Use for each activity. In properties, set Values as your dictionary and TypeArgument to System.Collections.Generic.KeyValuePair<TKey, TValue>
To display key, use item.Key and for value, item.Value properties
Capture

If this helps, please mark it as solution so that people facing similar issues can directly navigated to answer.

2 Likes

When trying to type argument of the for each loop I got the following error

Also I need to get the key of the dictionary for a specific index instead of looping through the dictionary.

HI @Aishwarya_Maggi,

You need to specify the Key and Value data types… Check the screenshot below…

1 Like

Hi, thanks for your reply. I have managed to change the data type but I get an error when trying to print the key

Cool…

For the dictionary key issue, try looking into these two posts… These two gives a good idea on how to loop through the dictionaries…

Let know if it doesn’t help… if it works, please mark the answer as the solution so it will be helpful for others as well :slight_smile:

Thanks

You have put the argument type to dictionary. it should be System.Collections.Generic.KeyValuePair<TKey, TValue>

@Aishwarya_Maggi
To get elements from specific index, Use,
dictTest.ElementAt(0).Key
dictTest.ElementAt(0).Value

6 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.