Recall & Review
beginner
What is the return type of an async method that returns a value in C#?
The return type is
Task<T>, where T is the type of the value returned. For example, async Task<int> returns an integer asynchronously.Click to reveal answer
beginner
How do you return a value from an async method?
Use the
return keyword followed by the value inside the async method. The value will be wrapped automatically in a Task<T>.Click to reveal answer
beginner
What keyword do you use to wait for the result of an async method that returns a value?
You use the
await keyword to wait for the completion of the async method and get its returned value.Click to reveal answer
intermediate
Can an async method return
void?Yes, but only for event handlers. Normally, async methods should return
Task or Task<T> to allow callers to await them and handle exceptions.Click to reveal answer
intermediate
What happens if you return a value directly from an async method without wrapping it in a Task?
You cannot return a value directly without wrapping it in
Task<T>. The compiler requires async methods to return Task, Task<T>, or void.Click to reveal answer
What is the correct return type for an async method that returns a string?
✗ Incorrect
Async methods that return a value must return Task, where T is the value type. Here, it's Task.
Which keyword do you use to get the result from an async method?
✗ Incorrect
The 'await' keyword pauses execution until the async method completes and returns its value.
What is the return type of an async method that does not return a value?
✗ Incorrect
Async methods that do not return a value should return Task, not void, except for event handlers.
Can you use 'await' inside a method that is not marked async?
✗ Incorrect
The 'await' keyword can only be used inside methods marked with the async modifier.
What happens if you forget to await an async method that returns a value?
✗ Incorrect
If you don't await, you get the Task object, not the actual result value.
Explain how to write an async method that returns an integer value and how to get that value when calling the method.
Think about the method signature and how to wait for the result.
You got /4 concepts.
Describe the difference between async methods returning Task, Task, and void.
Consider how each return type affects calling and error handling.
You got /4 concepts.