Complete the code to start a task that returns 5.
var task = Task.Run(() => [1]);The lambda returns the integer 5, so the task completes with result 5.
Complete the code to await the first task to complete among two tasks.
var firstFinished = await Task.WhenAny([1], Task.Delay(1000));
Task.WhenAny waits for the first task to finish. The task returning 10 finishes before the 1-second delay.
Fix the error in the code to get the result of the first completed task.
var firstFinished = await Task.WhenAny(task1, task2);
var result = firstFinished.[1];Task.WhenAny returns the first completed task. Access its Result property to get the value.
Fill both blanks to create two tasks and await the first to complete.
var task1 = Task.Run(() => [1]); var task2 = Task.Run(() => [2]); var first = await Task.WhenAny(task1, task2);
Task1 returns 100 immediately. Task2 waits 500ms then returns 200. The first task finishes immediately.
Fill all three blanks to create tasks and get the result of the first completed task.
var task1 = Task.Run(() => [1]); var task2 = Task.Run(() => [2]); var first = await Task.WhenAny(task1, task2); var result = first.[3];
Task2 returns 500 immediately. Task1 delays 200 ms then returns 24. The first completed task returns 500. Access Result to get the value.