Lambda表达式为“不”?(Lambda Expression for “not in”?)

2019-08-17 22:03发布

我有一个detailcollection集合,其中的每一个细节都有

code, price, name

并与一些代码字符串

string codes = "1,2,3";

我知道我可以使用数组string.Split()

string[] codesarray = codes.Split(',');

但我怎么能得到产品不codes

// the idea I have, but I would not like to have a loop
for (int i = 0; i < codesarray.Length; i++)
{
    detailcollection.Where(x => x.ope_idsku == codesarray[i])
}

我想是这样的:

detailcollection.Where(x => x.ope_idsku not in (codesarray))

Answer 1:

所选细节藏品哪个ID是不codesarray

detailcollection.Where (x=> !codesarray.Contains(x.ope_idsku))


文章来源: Lambda Expression for “not in”?