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. How to understand the phrase: "Asynchronous methods can have the following return types: ... any type that has an accessible GetAwaiter method", if the actual is not?
This code is not working:
using System.Runtime.CompilerServices;
async A Method() //Error CS1983 The return type of an async method must be void, Task, Task<T>, a task-like type, IAsyncEnumerable<T>, or IAsyncEnumerator<T>
{
await new A();
}
class A
{
public TaskAwaiter GetAwaiter()
{
return new TaskAwaiter();
}
}