删除Linq查询

时间:2012-11-28 06:19:01

标签: c# linq

我有列表列表courseTakenList.i想要过滤掉Completed,Dropped,Current,Schudeled中的状态。这是代码示例。

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

2 个答案:

答案 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子句