Loop through a dictionary and update it's Value

Hi guys
I have to work with dictionary and I want to change/update it’s Value in for each loop and save updated value in same dictionary.
But while doing this I am getting an error as “Some data modified in collection…”
Is their any clue how can we achieve this.

Please help
Thanks in advance

Hi @Anjali_Rani

1. Assign activity:
dictCopy = yourDictionary.ToDictionary(Function(entry) entry.Key, Function(entry) entry.Value)
2. For Each kvp In dictCopy
    If conditionToCheck(kvp.Value) 
    Then
           dictCopy(kvp.Key) = newValue
3. For Each kvp In dictCopy
    yourDictionary(kvp.Key) = kvp.Value

Hope it helps!!

For Each keyName in yourDict.Keys

  • Assign yourDict(keyName) = “some value”

This shouldn’t give you any issues because you’re looping through the array of keys.