title: C# How to remove a completed Task from Task[]
body: <p>I have an array of tasks running like this: (the number of tasks in the array is not fixed to 2, it can vary from time to time).</p>
  
  <pre><code>Task[] templates = new Task[2] {
    Task.Factory.StartNew( () =&gt; { x.foo(); }),
    Task.Factory.StartNew( () =&gt; { y.bar(); })
  };
  </code></pre>
  
  <p>Then I wait for any of them to finish.</p>
  
  <pre><code>int taskID;
  taskID = Task.WaitAny(templates);
  </code></pre>
  
  <p>As soon a task has finished I inspect various parameters inside the object (x or y) and if I don't have the result I expected I want to remove the finished task from the template array. something like this</p>
  
  <pre><code>template[taskID].RemoveThisTaskFromArray() // This is pseudo code to describe what I want.
  taskID = Task.WaitAny(templates);
  </code></pre>
  
  <p>I will do this in a loop until the task array <code>template[]</code> is empty or I decide to abort the operation and break out of the loop.</p>
  
  <pre><code>int taskID;
  do {
    taskID = Task.WaitAny(templates);
    if(template[taskID].valid == true) { // &lt;-- example of test for success
      // stop the remaining task in the template[] array.
      break;
    }
  
    // remove the completed task so we can use WaitAany() again.
  
  } while (template.Length &gt; 0);
  </code></pre>
  
  <p>It seems like <code>Task[]</code> doesn't support array members so There is no <code>Task[].RemoveAt()</code> function.
  I hope you get my point. Any way to solve this?</p>