使用StartsWith将值与字符串数组进行比较

pie*_*rre 10 .net c# linq arrays comparison

我有一个数组:

string[] exceptions = new string[] { "one", two", "one_1", "three" };
Run Code Online (Sandbox Code Playgroud)

..我希望能够说:

var result = from c in myCollection
             where not c.Property[3].Value.StartWith(exceptions)
             select c;
Run Code Online (Sandbox Code Playgroud)

所以我希望myCollection过滤只显示那些在例外数组Property[3].Value没有 StartWith值的记录.我知道StartsWith没有采集集合所以我不确定这是否可以通过LINQ实现.

这在LINQ中是否可行?!或者我是否想把我的问题变成LINQ解决方案?

编辑:我应该说,包含不是一个选项,因为我只想排除其属性以异常字符串开头的元素.

sll*_*sll 14

var result =  myCollection.Where(c =>  
                           exceptions.All(e => 
                                       !c.Property[3].Value.StartsWith(e));
Run Code Online (Sandbox Code Playgroud)

  • 使用"All",它不会返回任何结果.它应该是"任何". (2认同)