Linq 包含列表中的值

发布于 2024-11-25 03:28:13 字数 1429 浏览 1 评论 0原文

我很难解释这一点,但我希望一些代码能有所帮助:

        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 的 Guid 之一,则添加它。也许不同的方法会更好......有什么建议吗?

PS我知道该行不起作用,我将代码放在那里只是为了方便理解我需要什么。

编辑: 我想我已经解决了:

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())));
}

如果有人发现有什么问题,请告诉我。

its hard for me to explain this one, but i hope some code will help:

        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)));
        }

what i want to do is, if g.GamingProperties.Software contains one of the Guids of softChannels, then add it. maybe a diffrent approace will be better... any suggestions ?

p.s i know that line is not working, i have put the code there only for easy understanding what i need.

EDIT:
i think i have resolved it:

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())));
}

if anyone sees something wrong with that, please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷港 2024-12-02 03:28:13

您想要检查是否包含 softChannelsAny()

softChannels.Any(sc => g.GamingProperties.Software.Contains(sc))

事实上,您甚至可以编写

softChannels.Any(g.GamingProperties.Software.Contains)

You want to check whether Any() of the softChannels are contained:

softChannels.Any(sc => g.GamingProperties.Software.Contains(sc))

In fact, you can even write

softChannels.Any(g.GamingProperties.Software.Contains)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文