Run tasks at the same time in C#

C# interview exercise on Async & Generics, difficulty 2 of 3. Solve it in the editor beside a worked example; the tests run the moment you do.

Write FetchAll(ids, fetch) that calls fetch for every id and returns the results in the order of ids. The calls must be in flight at the same time: awaiting each one inside a loop would run them one after another. Start them all, then await Task.WhenAll.

Each exercise pairs a worked example with a twin problem to solve in a real editor; the tests run the moment you do. Progress is saved in your browser, and in your account if you sign in.

More Async & Generics in C#

All C# exercises · Other languages and frameworks