Search code examples
c#compact-frameworklambda

Lambda Expression for "not in"?


I have a detailcollection collection in which every detail has

code, price, name

And a string with some codes

string codes = "1,2,3";

I know I can get an array using string.Split()

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

But how can I get products not in 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])
}

I would like something like:

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

Solution

  • Selected details collection items which ids are not in codesarray:

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