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

标签 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 实现此解决方案以查找所有未以任何忽略项结尾的项?

最佳答案

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

关于c# - 如何使用 LINQ 查询不包含来自另一个列表的子字符串条目的字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2853473/

相关文章:

mongodb - 无法使用 MongoDB.Driver Include ProjectionDefinition 的 LINQ 表达式重载

c# - 如何找到当前用户具有 WriteProperty 访问权限的 ActiveDirectory 中的所有组?

c# - Linq on Entity Framework 与 SQL 存储过程的性能对比

c# - 用于获取包含 SQL IN() 的 EF 的 LINQ 的表达式,其中实体子属性等于值

c# - 构建与控制台和 DLL 相同的项目

c# - 密码框验证

c# - WCF 反序列化中的 XmlException : "Name cannot begin with ' <'" - in automatic property backing fields

c# - DPI 感知应用程序中的 SizeGripStyle

c# - LINQ To SQL、C#、MVC 4、模型助手中的连接问题

sql - 每特定时间选择一行