Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The return type of an async method must be void, Task, Task<T>, a task-like type (A task-like type is one that adheres to the pattern, described here, required by the C# specification), IAsyncEnumerable<T>, or IAsyncEnumerator<T>
The following sample generates CS1983:
// CS1983.cs (4,62)
using System.Collections.Generic;
class C
{
static async IEnumerable<int> M()
{
yield return await Task.FromResult(1);
}
}
Since IEnumerable.GetEnumerator
returns an IEnumerator<T>
whose MoveNext
method does not return a value of Task<T>
, it is not compatible with an async
method.
Use an interface that results in the invocation of method that returns a type of Task<T>
, for example, IAsyncEnumerable<T>
:
using System.Collections.Generic;
class C
{
static async IAsyncEnumerable<int> M()
{
yield return await Task.FromResult(1);
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: