Item
班级:
public class Item
{
public string Value { get; set; }
public ContentTypeEnum Type { get; set; }
}
ContentTypeEnum
枚举:
public enum ContentTypeEnum
{
Text,
PDF,
XML,
MP3
}
你的小组:
var textGroup = new List<ContentTypeEnum>() {
ContentTypeEnum.Text,
ContentTypeEnum.PDF,
ContentTypeEnum.XML
};
的输入列表Item
:
var items = new List<Item>() {
new Item() { Value = "custom PDF file", Type = ContentTypeEnum.PDF },
new Item() { Value = "My fav MP3", Type = ContentTypeEnum.MP3 },
new Item() { Value = "Paper", Type = ContentTypeEnum.Text }
};
该查询将仅返回具有textGroup
列表内类型的项目:
var textItems = items.Where(i => textGroup.Contains(i.Type)).ToList();
如此简单Console.WriteLine(item.Value)
,每个结果项都会打印:
custom PDF file
Paper