我有这个班
public class ConnectionResult { private int connectionPercentage; public int ConnectPercentage { get { return connectionPercentage; } } public ConnectionResult(int ip) { // Check connection and set connectionPercentage } }
并且我有一个经理可以获得ConnectionResult的几个列表,并对每个值进行计数,然后再按配置确定的特定数字.我的实现是这样的:
public class CurrentConnections { private static CurrentConnections inst; private CurrentConnections() { } public static CurrentConnections GetInstance { get { if (inst != null) { inst = new CurrentConnections(); } return inst; } } public int CountActiveConnections(params List<ConnectionResult>[] conns) { int rtVal = 0; foreach (List<ConnectionResult> connectionResult in conns) { foreach (var currConn in connectionResult) { if (currConn.ConnectPercentage > ACCEPTABLE_CONNECTION) { rtVal++; } } } return rtVal; } }
但是我想让它更好,所以我开始写在linq,我得到了
conns.Count(x => x.Count(y => y.ConnectPercentage > ACCEPTABLE_CONNECTION));
但是这给我一个错误,不能将类型’int’隐式转换为’bool’.
有没有办法计算在linq或我必须留下我写的?
btw,我是linq的新手