Complete the code to declare an asynchronous method.
public [1] Task<int> GetNumberAsync() { return Task.FromResult(5); }
The async keyword marks a method as asynchronous, allowing use of await inside it.
Complete the code to wait for the asynchronous method to finish and get the result.
int result = [1] GetNumberAsync();The await keyword waits for the asynchronous method to complete and returns its result.
Fix the error in the asynchronous method by completing the code.
public async Task<string> GetMessageAsync() {
[1] Task.Delay(1000);
return "Done";
}The await keyword is needed to wait for the delay to complete before continuing.
Fill both blanks to create an asynchronous method that returns the length of a string after a delay.
public [1] Task<int> GetLengthAsync(string text) { [2] Task.Delay(500); return Task.FromResult(text.Length); }
The method must be marked async and use await to wait for the delay.
Fill all three blanks to create an async method that awaits a delay, then returns the uppercase version of a string.
public [1] Task<string> ConvertToUpperAsync(string input) { [2] Task.Delay(700); return Task.FromResult(input[3]); }
The method is marked async, uses await to wait for the delay, and calls .ToUpper() on the input string.