string[] candidates = new string[] {
"Luke_jedi", "Force_unknown",
"Vader_jedi" , "Emperor_human", "r2d2_robot"
};
string[] disregard = new string[] {"_robot", "_jedi"};
//find those that aren't jedi or robots.
var nonJedi = candidates.Where(c=>
c.??? //likely using EndsWith() and Any()
);
您将如何使用 LINQ 实现此解决方案以查找所有未以任何忽略项结尾的项?
最佳答案
var nonJedi = candidates.Where(c => !disregard.Any(d => c.EndsWith(d)));
关于c# - 如何使用 LINQ 查询不包含来自另一个列表的子字符串条目的字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2853473/