LINQ有两个列表谓词?

use*_*410 2 c# linq

我有这样的代码:

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)

我想知道你是否能以某种方式计算每支球队的胜利,而不是先获得球队名称之后的球队名称.任何想法/

das*_*ght 5

您应该可以通过替换foreachSelect:

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)