How to loop through Dictionary?


#1

how to Read data from dictionary which I have initialized like

variable1= new Dictionary(Of String, String)From {{“0”, “string”}, {“1”, “string2”}}


#2

Dictionary_Loop.xaml (6.7 KB)


How to get and update the value of a dynamic key in a dictionary
#3

@vvaidya,
may I know why System.Collections.Generic.KeyValuePair used instead of Dictionary in FOR loop’s Argument type?

Thanks in advance :slight_smile:


#4

Because Dictionary is collection of KeyValuePairs.


#5

Hi There…
could you please explain me a simple example of Add_To_Dictionary and Get_From_Dictionary…and how to set Key and Values


#6

Hi @DK_1994,

Before adding items to the dictionary it must be initialized. The default value of the Dictionar object is Nothing.

To initialize it you can use an Assign activity or define default value in the Variables pane.

The value should be new Dictionary(Of String, String), if both your key and value are strings.

Use “Add to Dictionary” activity to add the Key and value in the Dictionary.
image

Get the value from the Dictionary is easy.
Dict(“keyname”)

Regards,
Arivu


The best way for scraping
#7

sorry but,how to initialize the dictionary…means …I know the structure and syntax…but no idea about it…how to change it as per requirement…

thanks for above reply


#8

Hi @DK_1994,

Based on your requirement you can assign.

For example if you are using key value pair as string and value also string

Dictionary dict= new Dictionary(Of string,string)

Regards,
Arivu


#9

image
for using key-value make correct you are using correct dictionary

Incorrect: System.Collections.Generic.Dictionary<System.String, System.String>
Correct: System.Collections.Generic.KeyValuePair<System.String, System.String>


#10

Hey, what is the difference between the the two dictionaries? And why would u use one over the other?

Regarding the dictionary (not key value pair), if it was in a for loop (PrefNames is the dict) like in the picture, how would I write the value of each object in the dict?
image
Currently, it reads out the entire object (key and value) like so: “[key1, value1]”

Also, how do u add to the keyValuePair, since the ‘add to dictionary’ activity doesn’t work on it.

Thank you.