当前位置 : 主页 > 编程语言 > c语言 >

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

来源:互联网 收集:自由互联 发布时间:2021-06-25
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=
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)));
网友评论