C# 将并发命令值转换为列表

C# 将并发命令值转换为列表,c#,list,concurrentdictionary,C#,List,Concurrentdictionary,如何将并发字典值转换为列表,下面是我尝试的代码 //this collection will maitain server connections/ server can support multiple connections public static readonly IDictionary<string, ISet<ConnectionManager>> SereverConnections = new ConcurrentDictionary<string

如何将并发字典值转换为列表,下面是我尝试的代码

//this collection will maitain server connections/ server can support multiple connections
public static readonly IDictionary<string, ISet<ConnectionManager>> SereverConnections = new ConcurrentDictionary<string, ISet<ConnectionManager>>();
//Get All Server Connections List
public static IList<ConnectionManager> GetAllServerConnections()
{

    IList<ConnectionManager> connectionList = new List<ConnectionManager>(Global.SereverConnections.Values);
    return connectionList;
    //return Global.SereverConnections.Values.ToList();
    //return (Gloconnections.ToList() ?? Enumerable.Empty<ConnectionManager>().ToList());
}
//此集合将维护服务器连接/服务器可以支持多个连接
公共静态只读IDictionary SereverConnections=new ConcurrentDictionary();
//获取所有服务器连接列表
公共静态IList GetAllServerConnections()
{
IList connectionList=新列表(Global.SereverConnections.Values);
返回连接列表;
//返回Global.SereverConnections.Values.ToList();
//返回(Gloconnections.ToList()??Enumerable.Empty().ToList());
}
编译时错误:

cannot convert from 'System.Collections.Generic.ICollection<System.Collections.Generic.ISet<ChatServer.ConnectionManager>>' to 'int'
无法从“System.Collections.Generic.ICollection”转换为“int”

您正在传递ICollection内部列表(intsize)构造函数。当然,编译器会抱怨ICollection转换成整数。 此外,您还需要包含集合集合,因此您的注释代码将无法工作,这样您就可以获得所有不同的连接:

public static IList<ConnectionManager> GetAllServerConnections()
{
    return Global.SereverConnections.SelectMany(x=> x.Value).Distinct().ToList();
}
public静态IList GetAllServerConnections()
{
返回Global.SereverConnections.SelectMany(x=>x.Value).Distinct().ToList();
}

您正在传递ICollection内部列表(intsize)构造函数。当然,编译器会抱怨ICollection转换成整数。 此外,您还需要包含集合集合,因此您的注释代码将无法工作,这样您就可以获得所有不同的连接:

public static IList<ConnectionManager> GetAllServerConnections()
{
    return Global.SereverConnections.SelectMany(x=> x.Value).Distinct().ToList();
}
public静态IList GetAllServerConnections()
{
返回Global.SereverConnections.SelectMany(x=>x.Value).Distinct().ToList();
}
您是否尝试过以下方法:

IList<ConnectionManager> connectionList = Global.SereverConnections.SelectMany(x=>x.Value).ToList();
IList connectionList=Global.SereverConnections.SelectMany(x=>x.Value.ToList();
您是否尝试过以下方法:

IList<ConnectionManager> connectionList = Global.SereverConnections.SelectMany(x=>x.Value).ToList();
IList connectionList=Global.SereverConnections.SelectMany(x=>x.Value.ToList();
列出connectionList=Global.SereverConnections.Values.ToList();
这将为您提供一个“ISet”列表,这实际上取决于如果您需要更进一步,ISet是什么。

list connectionList=Global.SereverConnections.Values.ToList();

这将为您提供一个“ISet”列表—如果您需要进一步了解,这实际上取决于ISet是什么。

我已经尝试过,但不接受IList connectionList=new list(Global.SereverConnections.Values.Select(x=>x));但是我尝试过不接受IList connectionList=new List(Global.SereverConnections.Values.Select(x=>x));我想知道为什么我的问题被否决?有什么理由让我可以提高我的自我吗?不知道为什么你被否决了。。。据我所知,这不是一个不合理的问题。。。显然有人认为这值得回答。但请务必标出最适合你的答案。我想知道为什么我的问题被否决了?有什么理由让我可以提高我的自我吗?不知道为什么你被否决了。。。据我所知,这不是一个不合理的问题。。。显然有人认为这值得回答。但请务必标出最适合你的答案。赞扬某人。