如何使用LINQ查询不包含来自另一个列表的子字符串条目的字符串列表

时间:2010-05-17 22:55:31

标签: c# linq

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实现此解决方案,以找到所有不以任何无视项目结束的解决方案?

2 个答案:

答案 0 :(得分:7)

var nonJedi = candidates.Where(c => !disregard.Any(d => c.EndsWith(d)));

答案 1 :(得分:0)