C# - LINQ Statements with OR clauses

Posted by user70192 on Stack Overflow See other posts from Stack Overflow or by user70192
Published on 2010-03-13T16:57:10Z Indexed on 2010/03/13 17:05 UTC
Read the original article Hit count: 226

Filed under:
|

Hello,

I am trying to use LINQ to return a list of tasks that are in one of three states. These states are:

10 - Completed 11 - Incomplete 12 - Skipped

The state is available through a property called "TaskStateID". I can do this in LINQ with just one state as shown here:

var filteredTasks = from task in tasks
                    select task;

// Do stuff with filtered tasks

string selectedComboBoxValue = GetFilterComboBoxValue();
if (selected ComboBoxValue == 3)
{
  filteredTasks = filteredTasks.Where(p => p.TaskStateID == 10); // How do I use an 'OR' here to say p.TaskStateID == 10 OR p.TaskStateID == 11 OR p.TaskStateID == 12
}

As shown in the comment above, how do I use an 'OR' in a LINQ statement to say p.TaskStateID == 10 OR p.TaskStateID == 11 OR p.TaskStateID == 12?

Thank you

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ