表示“不在”的Lambda表达式

本文关键字:Lambda 表达式 不在 表示 | 更新日期: 2023-09-27 18:05:15

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

表示“不在”的Lambda表达式

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

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