Complete the code to declare an async method that returns an integer.
public async Task<[1]> GetNumberAsync() { return 42; }
The method returns a Task wrapping an integer, so the return type is Task<int>.
Complete the code to await an async method and get its result.
int result = await GetNumberAsync();
Console.WriteLine([1]);await inside Console.WriteLine without storing the result.You should print the variable result which holds the awaited value.
Fix the error in the async method to correctly return a string value.
public async Task<string> GetMessageAsync() {
[1] "Hello";
}await without returning a value.yield in an async method.Async methods returning a value must use return to send back the result.
Fill both blanks to create a dictionary comprehension that filters async results.
var results = new Dictionary<string, int> {
{"score", [1],
{"count", [2]
};To get the actual values from async methods, you must await them.
Fill all three blanks to create an async method that returns a dictionary with awaited values.
public async Task<Dictionary<string, int>> GetDataAsync() {
return new Dictionary<string, int> {
{"a", [1],
{"b", [2],
{"c", [3]
};
}Each async method call must be awaited to get the integer values before returning the dictionary.