C# “不在”的 Lambda 表达式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15574952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Lambda Expression for "not in"?
提问by angel
I have a detailcollection
collection in which every detail has
我有一个detailcollection
集合,其中每个细节都有
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.Split()
string[] codesarray = codes.Split(',');
But how can I get products not in codes
?
但是我怎样才能得到不在里面的产品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))
采纳答案by Zbigniew
Selected details collection items which ids are not in codesarray
:
id 不在的选定详细信息集合项目codesarray
:
detailcollection.Where (x=> !codesarray.Contains(x.ope_idsku))