Hi all, I was trying to play with Dictionaries and wanted t be able to print the key as well as the value in the same for each loop, but no matter what i do, it givs an error stating:
For Each: Unable to cast object of type ‘System.Collections.Generic.KeyValuePair
2[System.String,System.String]' to type 'System.Collections.Generic.Dictionary2[System.String,System.String]’.
I have tried to change the distionary to String, String and the for each to the same or String, object and the for each to the same, but I cant get it to work.
So how can I print the key and value in the same for each loop? I have attached the sample file
Thank you in advance.
Dictionary Workflow.zip (5.5 KB)
Test to change the For Loop TypeArgument to KeyValuePair. Then in Write Line:
item.Key + " = " + item.Value
Adding to what @ptrobot said. Take a look at the solution in this thread. It contains some explanation and a sample code.
Hi @Sidney_Vogel ,
You could also try looping through the Keys and reference the Values using the dictionary itself
Key In in_exceldata.Keys
So could you give this a try instead?
key+ " " + in_exceldata(key).ToString
Also, I’ve changed the ArgumentType to String →
BlankProcess1_v1.zip (5.6 KB)
Have a look on the below video
Thank you this was helpful
Hi @ashwin.ashok Thank you for your example, this worked for me
Hi @jeevith Thank you for your explanation
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.