我想使用 myFilters 从 myCollection 中选择元素进行过滤:
var myFilters = new List<string> {"111", "222"};
var myCollection = new List<SomeClass> {
new SomeClass ("111"),
new SomeClass ("999")
};
from filter in myFilters
from item in myCollection
where item.Name == filter
select item
将返回“111”项目。
但是,如果 myFilters 为空,我想从 myCollection 返回所有项目。
var myFilters = new List<string> ();
var myCollection = new List<SomeClass> {
new SomeClass ("111"),
new SomeClass ("999")
};
// Here's where I'm lost...
from filter in myFilters
from item in myCollection
where item.Name == filter
select item
将返回所有项目(“111”和“999”)。