Sometimes I want to await a bunch of tasks in parallel but the tasks themselves depend on some condition. I could write
var tasks = new List<Task> { DoThisAsync(), DoThatAsync() };
if (condition) tasks.Add(AlsoDoOtherStuffAsync());
await Task.WhenAll(tasks);
But what if I write
var task = Task.WhenAll(DoThisAsync(), DoThatAsync());
if (condition) task = Task.WhenAll(task, AlsoDoOtherStuffAsync());
await task;
Is there any difference in behavior between the two versions? Is one preferred or mode idiomatic than the other?