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