0

我有 List List courseTakenList。我想过滤掉Completed,Dropped,Current,Schudeled. 这是代码示例。

courseTakenList = (from courseTaken in courseTakenList
                      select new Course
                      {
                           Status = "Scheduled"?"COMPLETE"?"Dropped"? "Current"
                      }).ToList();
4

2 回答 2

4

你可以做得更简洁

var statuslist= {"Completed","Dropped","Current","Schudeled"};

var courses = courseTakenList.Where(courseTaken => 
                       statuslist.Contains(courseTaken.Status);
于 2012-11-28T08:24:45.377 回答
2

Linq In像这样的查询将解决您的问题

var statuslist= {"Completed","Dropped","Current","Schudeled"};

var query = from courseTaken in courseTakenList
            where statuslist.Contains( courseTaken .Status )
            select courseTaken ;

注意:根据需要更改选择子句

于 2012-11-28T06:23:31.417 回答