Lambda表达式用于“not in”?

21

我有一个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))
1个回答

43

选择那些id不在codesarray中的详细信息收集项:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接