1

从 Observable 集合中,我想过滤名称为 aaa、bbb、ccc、ddd、eee 的项目。这该怎么做?

public class Item
{
public string ItemName {get; set;}
public int ItemNumber {get; set;}
}

public ObservableCollection<Item> _items;

public List<string> searchItems = new List<string>(5);
searchItems.Add("aaa");
searchItems.Add("bbb");
searchItems.Add("ccc");
searchItems.Add("ddd");
searchItems.Add("eee");

我在 linq 中尝试了一些 .. 但我不知道如何处理列表..

var filteredItems = from item in _items
                    where _items.Any(x => x.ItemName == "aaa")
                    select x;
4

1 回答 1

5

您可以使用包含;

var filteredItems = from item in _items
                    where _items.Any(x => searchItems.Contains(x.ItemName))
                    /*select x;*/
                    select item;
于 2013-03-18T11:25:48.640 回答