比较值使用StartsWith字符串数组 [英] Compare value to array of strings using StartsWith
问题描述
我有一个数组:
的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));
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));
这篇关于比较值使用StartsWith字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!