Search code examples
c#.netlinqfiltering

Exclude list items that contain values from another list


There are two lists:

List<string> excluded = new List<string>() { ".pdf", ".jpg" };
List<string> dataset = new List<string>() {"valid string", "invalid string.pdf", "invalid string2.jpg","valid string 2.xml" };

How can I filter-out values from the "dataset" list which contain any keyword from the "excluded" list?


Solution

  • var results = dataset.Where(i => !excluded.Any(e => i.Contains(e)));