Sort List By Boolean I have a class called Task that contain a member boolean variable Completed.

I created a list of Task objects in a variable called Tasks. 

I have the following code, which sorts the objects depending on whether the Task is completed. (I want the incompleted tasks to be in the list first)

private List&lt;Task&gt; GetSortedTask(List&lt;Task&gt; tasks)
{
    List&lt;Task&gt; completedTaskList = new List&lt;Task&gt;();
    List&lt;Task&gt; incompleteTaskList = new List&lt;Task&gt;();

    for (int i = 0; i &lt; tasks.Count; i++)
    {
        HelperObject T = task[i].getHelperObject();

        if (T != null &amp;&amp; T.Completed)
            completedTaskList.Add(tasks[i]);
        else
            incompletetaskList.Add(tasks[i]);
    }

    //merge the two lists together
    imcompleteTaskList.AddRange(completedTaskList);

    return incompleteTaskList;
}


Is there a way to do this without creating so many lists? Thanks in advance

EDIT: Made my question a bit more specific since orderBy seems to be the correct answer, however my problem may be a bit more complicated than that.
I think my original comment in regards to using OrderBy could still possibly still even with your latest edits (and BTW that code does not compile, there is no declared task object :)).

How about something like:

var query = from task in tasks
            let helperTask = task.getHelperObject()
            select new
            {
               Completed = helperTask != null &amp;&amp; helperTask.Completed,
               Task = task
            };

return query.OrderBy(p =&gt; p.Completed).Select(p =&gt; p.Task).ToList();


UPDATE:
Another excellent option suggested by svick to further refine and remove the anonymous object selection is something along the lines of:

var query = from task in tasks
            let helperTask = task.getHelperObject()
            orderby helperTask != null &amp;&amp; helperTask.Completed
            select task;

return query.ToList();


I guess if I could I would do away with ToList() altogether and return IEnumerable but that depends on the context of the operation.  I also personally like using an intermediate variable here (query) as I think it just helps readability.  All to their own on that front though.