I'm completely confused.
It says here:
Async methods can have the following return types:
Task, for an async method that performs an operation but returns no value.
Task <TResult>, for an async method that returns a value.
void, for an event handler.Starting with C# 7.0, any type that has an accessible
GetAwaitermethod. The object returned by theGetAwaitermethod must implement theSystem.Runtime.CompilerServices.ICriticalNotifyCompletioninterface.Starting with C# 8.0,
IAsyncEnumerable<T>, for an async method that returns an async stream.
Question 1. Why write about tasks if
TaskandTask<Result>fit the "GetAwaiter" criterion?Question 2. Here I got the answer that the
IAsyncEnumerable<T>point is more about await. Then what about everything else? Can someone clearly explain what each keyword applies to without big examples?What types can return async methods - list or criteria? And what types can the await keyword or their criteria apply to?
Examples of answers how I would like:
Keyword async applicable for return values (async methods can return values): type1, type2, typeN, or any type with specific characteristics (for example ... some characteristics).
Keyword await applicable for awaitable types: type1, type2, typeN, or type with specific characteristics (for example contains GetAwaiter).
- Question 3. Speaking of void we mean only the return value of the async method. Can void be the awaitable type? Can someone give an example of a void awaiting?