Quantcast
Channel: Answers for "Out of sync error when iterating over a Dictionary"
Browsing all 8 articles
Browse latest View live

Answer by Julien.Lynge

One of the restrictions of a foreach loop is that you can't change the underlying thing you're iterating over. If you change a dictionary while you're iterating through it, the program has no idea if...

View Article


Answer by furic

Added to @Julien's answer, instead of using: foreach (string s in dict.Keys) { dict [s] = ... Use: List keys = new List (dict.Keys); foreach (string key in keys) { dict [key] = ...

View Article


Answer by AndyMartin458

Before I saw @furic 's answer to create a list out of the keys, I did this. Thought someone might find it useful. Item[] items = new Item[m_dict.Count]; m_dict.Values.CopyTo(items, 0); foreach (Item...

View Article

Answer by Trojaner

foreach (string s in dict.Keys.ToList()) { dict [s] = ... Would be the simplest solution I guess

View Article

Answer by Julien-Lynge

One of the restrictions of a foreach loop is that you can't change the underlying thing you're iterating over. If you change a dictionary while you're iterating through it, the program has no idea if...

View Article


Answer by furic

Added to @Julien's answer, instead of using: foreach (string s in dict.Keys) { dict [s] = ... Use: List keys = new List (dict.Keys); foreach (string key in keys) { dict [key] = ...

View Article

Answer by AndyMartin458

Before I saw @furic 's answer to create a list out of the keys, I did this. Thought someone might find it useful. Item[] items = new Item[m_dict.Count]; m_dict.Values.CopyTo(items, 0); foreach (Item...

View Article

Answer by Trojaner

foreach (string s in dict.Keys.ToList()) { dict [s] = ... Would be the simplest solution I guess

View Article

Browsing all 8 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>