where子句如下:
Where item.field == "value"
如何将LINQ中的语句更改为:
Where item.field in ("value1","value2","value3")
看起来很简单,但行不通。
Thanks in advance
首先在变量中声明你的"in"值集合:
var collection = new[] { "value1","value2","value3" };
然后在query:
中使用...
where collection.Contains(item.field)
...
或者在lambda语法中(假设您有一个正在搜索的集合):
var lookup = new[] { "value1","value2","value3" };
var result = collection.Where(x=> lookup.Contains(x)).ToArray();