Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an asynchronous method.
C Sharp (C#)
public async Task [1]() { await Task.Delay(1000); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names without 'Async' suffix for async methods.
✗ Incorrect
The method name 'ExecuteAsync' clearly indicates it is asynchronous, which is a common naming convention.
2fill in blank
mediumComplete the code to await an asynchronous method call.
C Sharp (C#)
await [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Awaiting methods that are not asynchronous.
✗ Incorrect
You await the asynchronous method named 'ExecuteAsync' to pause execution until it completes.
3fill in blank
hardFix the error in the async method by adding the missing keyword.
C Sharp (C#)
public [1] Task<int> GetNumberAsync() { return Task.FromResult(42); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the 'async' keyword on asynchronous methods.
✗ Incorrect
The 'async' keyword is required to mark the method as asynchronous.
4fill in blank
hardFill both blanks to create a dictionary comprehension that filters async tasks by completion status.
C Sharp (C#)
var completedTasks = tasks.Where(t => t.[1]).ToDictionary(t => t.Id, t => t.[2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Status' instead of 'IsCompleted' for filtering.
Using 'StartTime' instead of 'Result' for dictionary values.
✗ Incorrect
Use 'IsCompleted' to filter completed tasks and 'Result' to get their results in the dictionary.
5fill in blank
hardFill all three blanks to create an async method that returns the length of a string after a delay.
C Sharp (C#)
public async Task<int> [1](string input) { await Task.[2](500); return input.[3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Wait' instead of 'Delay' causes blocking instead of async wait.
Returning 'input.Length()' with parentheses causes error because Length is a property.
✗ Incorrect
The method name is 'GetLengthAsync', it awaits 'Task.Delay(500)', then returns 'input.Length'.