【转】集合已修改;可能无法执行枚举操作

转自:http://bbs.csdn.net/topics/370152213

#2楼

foreach 值是只读的。

所以只能用 for

Dictionary<int, int> d = new Dictionary<int, int>();
    d.Add(1, 1);
    var target = d.ToList();
    for (int index = 0; index < target.Count; index++)
      XX.Write(target[index].Key + " = " + target[index].Value);

原文地址:https://www.cnblogs.com/wdw31210/p/4081270.html