开发者

How to use LINQ to query list of strings that do not contain substring entries from another list

开发者 https://www.devze.com 2022-12-31 15:17 出处:网络
string[] candidates = new string[] { \"Luke_jedi\", \"Force_unknown\", \"Vader_jedi\" , \"Emperor_human\", \"r2d2_robot\"
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()
              ); 

How would you implement this solution using LINQ to find all those tha开发者_如何学运维t do not end with any of the disregards items?


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


The NOT IN clause in LINQ to SQL
http://introducinglinq.com/blogs/marcorusso/archive/2008/01/14/the-not-in-clause-in-linq-to-sql.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消