C# StackOverflowXeption将字典转换为列表

C# StackOverflowXeption将字典转换为列表,c#,stack-overflow,C#,Stack Overflow,我不是C语言的高手,我在这段代码中得到了一个堆栈溢出验证: private Dictionary<T, V> collection; internal List<KeyValuePair<T, V>> ToList() { return collection.ToList(); //the VS debugger breaked here } 下面是完整的课程: 希望有人能找到堆栈溢出的例子 以下是更多信息:$ internal QueuedDi

我不是C语言的高手,我在这段代码中得到了一个堆栈溢出验证:

private Dictionary<T, V> collection;
internal List<KeyValuePair<T, V>> ToList()
{
    return collection.ToList(); //the VS debugger breaked here
}
下面是完整的课程: 希望有人能找到堆栈溢出的例子

以下是更多信息:$

  internal QueuedDictionary<int, RoomUser> UserList
        {
            get
            {
                return userlist;
            }
        }

    internal List<RoomUser> GetRoomUsers()
    {
        List<KeyValuePair<int, RoomUser>> users = UserList.ToAList();

        List<RoomUser> returnList = new List<RoomUser>();
        foreach (KeyValuePair<int, RoomUser> pair in users)
        {
            if (!pair.Value.IsBot)
                returnList.Add(pair.Value);
        }

        return returnList;
    }
从字典显式创建新的KeyValuePair元素,然后列出它:

internal List<KeyValuePair<T, V>> ToList()
{
    return collection.Select(kvp => new KeyValuePair<T,V>(kvp.Key, kvp.Value).ToList(); 
}
应该执行您想要的操作

编辑我希望你的代码也能工作。可能是Dictionary的.ToList方法执行类似于.Selectx=>x.Value的操作,而不是返回列表。
但这只是我的猜测。

请在这里发布所有相关代码。如果Pastebin发生故障,我们如何查看您的代码?查看调用堆栈,是否看到对ToList方法的长字符串调用?调用堆栈中没有任何内容:。我在两天内运行了1次此验证:谢谢希望您的代码不再提供堆栈溢出验证谢谢: