// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; namespace E { public class Data { public int Id { get; set; } public List Vals { get; set; } } public class Program { public static void Main(string[] args) { List total = new List { new Data { Id=1, Vals=new List { "A", "X", "Y" }}, new Data { Id=2, Vals=new List { "A", "B", "C" }}, new Data { Id=3, Vals=new List { "D", "X", "Y" }} }; List targets = new List{ "A", "B", "C" }; // all match foreach(Data d in total.Where((o) => o.Vals.Intersect(targets).Count() == targets.Count)) { Console.WriteLine(d.Id); } // at least one match foreach(Data d in total.Where((o) => o.Vals.Intersect(targets).Count() > 0)) { Console.WriteLine(d.Id); } // none match foreach(Data d in total.Where((o) => o.Vals.Intersect(targets).Count() == 0)) { Console.WriteLine(d.Id); } } } }