比较值使用StartsWith字符串数组数组、字符串、StartsWith

2023-09-04 09:06:10 作者:△ 三分流氓气 ▌▎

我有一个数组:

 的String []例外=新的String [] {一,二,one_1,三};
 

。我希望能够说:

  VAR的结果=从C MyCollection中
             哪里都不c.Property [3] .Value.StartWith(例外)
             选择C;
 

所以,我想 MyCollection的来进行过滤,只显示那些记录属性[3] .value的确实< STRONG>不可以 StartWith A的异常数组值。我知道StartsWith不采取集合,所以我不能确定这是可以通过LINQ与否。

这是可能的LINQ?还是我试图硬塞进我的问题转化为LINQ的解决方案?

编辑:我应该说,包含是不是一种选择,因为我只想排除元件,其startswith除了字符串属性

解决方案

  VAR的结果= myCollection.Where(C =&GT;
                           exceptions.All(E =&GT;
                                       !c.Property [3] .Value.StartsWith(E));
 
c语言 用二维数组和字符串输入输出一个表格

I have an array:

string[] exceptions = new string[] { "one", two", "one_1", "three" };

.. I want to be able to say:

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

So I want myCollection to be filtered to only show those records whose Property[3].Value does not StartWith a value in the exceptions array. I know StartsWith doesn't take a collection so I'm unsure if this is possible via LINQ or not.

Is this possible in LINQ?! Or am I trying to shoehorn my problem into a LINQ solution?

EDIT: I should say, Contains is not an option since I only want to exclude elements whose property startswith the exception string.

解决方案

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