排除包含其他列表中的值的列表项

lek*_*kso 18 .net c# linq filtering

有两个列表:

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" };
Run Code Online (Sandbox Code Playgroud)

如何从"数据集"列表中筛选出包含"排除"列表中任何关键字的值?

Mar*_*zek 26

var results = dataset.Where(i => !excluded.Any(e => i.Contains(e)));
Run Code Online (Sandbox Code Playgroud)


Maj*_*adi 10

// Contains four values.
int[] values1 = { 1, 2, 3, 4 };

// Contains three values (1 and 2 also found in values1).
int[] values2 = { 1, 2, 5 };

// Remove all values2 from values1.
var result = values1.Except(values2);
Run Code Online (Sandbox Code Playgroud)

https://www.dotnetperls.com/except


aba*_*hev 6

尝试:

var result = from s in dataset
             from e in excluded 
             where !s.Contains(e)
             select e;
Run Code Online (Sandbox Code Playgroud)