我有这样的代码:
string[] teamNames = teams.Select(x => x.Name).ToArray();
List<int> wins = new List<int>();
foreach(var _team in teamNames)
{
wins.Add(matches.Count(x =>
((x.Team1 == _team && x.Maps.Count(map => map.Score1 > map.Score2) > x.Maps.Count(map => map.Score2 > map.Score1)) ||
(x.Team2 == _team && x.Maps.Count(map => map.Score2 > map.Score1) > x.Maps.Count(map => map.Score1 > map.Score2))
)));
}
Run Code Online (Sandbox Code Playgroud)
我想知道你是否能以某种方式计算每支球队的胜利,而不是先获得球队名称之后的球队名称.任何想法/
您应该可以通过替换foreach为Select:
var wins = teamNames
.Select(_team =>
matches.Count(x =>
((x.Team1 == _team && x.Maps.Count(map => map.Score1 > map.Score2) > x.Maps.Count(map => map.Score2 > map.Score1)) ||
(x.Team2 == _team && x.Maps.Count(map => map.Score2 > map.Score1) > x.Maps.Count(map => map.Score1 > map.Score2))
))
)
.ToArray();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
162 次 |
| 最近记录: |