Linq Contains a value in a list.

It's hard for me to explain this, but I hope some code helps:

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, if g.GamingProperties.Software contains one of the softChannels Guides, then add it. maybe a great solution would be better ... any suggestions?

ps I know that the line does not work, I put the code there just to easily understand what I need.

EDIT: I think I decided:

 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 this, please let me know.

+4
source share
1 answer

You want to check if Any() softChannels for softChannels :

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

In fact, you can even write

 softChannels.Any(g.GamingProperties.Software.Contains) 
+6
source

All Articles