Click here to Skip to main content
15,935,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to replace the values of a key in a dictionary while iterating?
Updated 17-Jun-15 18:38pm

Share this answer
You don't need to iterate to change the dictionary.
dict.Add(newKey, value);

You will not be able to change the collection while you are iterating through it.
A way out is to create a temporary list of key value pairs, iterate through this list and change the key as appropriate.
Share this answer
See this post to help you,[^], you can't rename keys once that have been added to a Dictionary, first remove then add a new.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900