Skip to main content
 首页 » 编程设计

c#之Linq 计数,问题

2024年02月24日22kenshinobiy

我有这个简单的查询 ->

var games = 
from p in _oListGames 
where p.Visitor == team.ID 
select p 

我想用 p.Visitor 从该列表 (_oListGames) 中获得的游戏总数来订购此选择

我该怎么做?

我想按照他们当前拥有的访客游戏数量来排序 var“游戏”。

请您参考如下方法:

我假设您的意思是按每场比赛的主场球队的客场比赛数量排序:

var games = 
from p in _oListGames 
where p.Visitor == team.ID 
orderby _oListGames.Count(g => p.Home == g.Visitor)  
select p;