我有列表列表courseTakenList.i想要过滤掉Completed,Dropped,Current,Schudeled
中的状态。这是代码示例。
courseTakenList = (from courseTaken in courseTakenList
select new Course
{
Status = "Scheduled"?"COMPLETE"?"Dropped"? "Current"
}).ToList();
答案 0 :(得分:4)
你可以做得更简洁
var statuslist= {"Completed","Dropped","Current","Schudeled"};
var courses = courseTakenList.Where(courseTaken =>
statuslist.Contains(courseTaken.Status);
答案 1 :(得分:2)
Linq In
查询将解决您的问题
var statuslist= {"Completed","Dropped","Current","Schudeled"};
var query = from courseTaken in courseTakenList
where statuslist.Contains( courseTaken .Status )
select courseTaken ;
注意:根据需要更改select子句