Linq包含列表中的值
本文关键字:列表 包含 Linq | 更新日期: 2023-09-27 18:02:20
我很难解释这一点,但我希望一些代码会有所帮助:
var softChannels = channels.ByPath("/software/").Children.Where(c => c.StateProperties.IsActive);
var tmpGames = new List<MyCms.Content.Games.Game>();
// Get games only from active game channels
foreach (var channel in channels.ByPath("/gameslivecasinodirectcom/game-channels/").Children.Where(c => c.StateProperties.IsActive))
{
// QUESTION IS ABOUT THIS LINE
tmpGames.AddRange(oGames.AllActive.Where(g => g.StateProperties.Channels.Contains(channel.Guid) && g.GamingProperties.Software.Contains(softChannels)));
}
我想做的是,如果g.GamingProperties.Software
包含softChannels的Guids之一,然后添加它。也许另一种方法会更好……有什么建议吗?
p。我知道那行不行,我把代码放在那里只是为了方便理解我需要的东西。
编辑:我想我已经解决了:
var softChannels = channels.ByPath("/software/").Children.Where(c => c.StateProperties.IsActive).Select(c => c.Guid);
var tmpGames = new List<MyCms.Content.Games.Game>();
// Get games only from active game channels
foreach (var channel in channels.ByPath("/gameslivecasinodirectcom/game-channels/").Children.Where(c => c.StateProperties.IsActive))
{
tmpGames.AddRange(oGames.AllActive.Where(g => g.StateProperties.Channels.Contains(channel.Guid) && softChannels.Contains(g.GamingProperties.Software.Trim())));
}
如果有人发现有什么问题,请告诉我
检查softChannels
中是否包含Any()
:
softChannels.Any(sc => g.GamingProperties.Software.Contains(sc))
事实上,你甚至可以写
softChannels.Any(g.GamingProperties.Software.Contains)