我正在尝试遍历包含对象作为值的字典:
foreach (KeyValuePair<int, CMapPool_Entry> Entry in MapPool)
{
   this.SendConsoleMessage(Entry.Value.Map);
}
下面你可以看到 CMapPool_Entry 的类
public class CMapPool_Entry
{
    public string Map;
    public string Mode;
    public int Rounds;
    public int Index;
    public int Votes;
    public bool Nominated;
    public string Nominator;
    public CMapPool_Entry(string map, string mode, int rounds, int index, string Nominator_LeaveEmptyStringIfNone)
    {
        this.Map = map;
        this.Mode = mode;
        this.Rounds = rounds;
        this.Index = index;
        // If Nominator isn't empty, set map to nominated
        if (Nominator_LeaveEmptyStringIfNone != "")
        {
            this.Nominated = true;
            this.Nominator = Nominator_LeaveEmptyStringIfNone;
        }
    }
    public void AddVote()
    {
        this.Votes++;
    }
    public void RemoveVote()
    {
        if (this.Votes > 0)
            this.Votes--;
    }
}
这里还可以看到 SendConsoleMessage 方法:
    private void SendConsoleMessage(string message)
    {
        this.ExecuteCommand("procon.protected.pluginconsole.write", String.Format("{0}", message));
    }
对我来说它看起来会起作用,我已经阅读了如何从 foreach 中的字典中编辑值会产生以下错误:“集合已修改;枚举操作可能无法执行。”
但是为什么我会收到这个错误?我没有编辑任何值,我只是在阅读它们,对吗?如果 CObject 是 string 或 int ,它可以正常工作,但如果它是一个对象,它就会发疯。我做错了什么,我该怎么办?
编辑:经过进一步调试后,我注意到 Entry.Key 可以很好地使用,但是一旦我触摸 Entry.Value,我就会收到错误消息。由于某种原因,我随机收到了两个不同的错误:
- “集合已修改;枚举操作可能无法执行。”
 - “给定的键不在字典中。”
 
有任何想法吗?或者以对象为值的枚举字典根本不起作用?