It says here:
- Starting with C# 8.0,
IAsyncEnumerable<T>
, for an async method that returns an async stream.
Question. In addition to the specified example with foreach
, is it possible to use more the await
with IAsyncEnumerable<T>
somehow, or is it designed specially for foreach
? I think yes, but not sure. Perhaps there are other purposes.
await foreach (var number in GetNumbersAsync())
{
Console.WriteLine(number);
}
async IAsyncEnumerable<int> GetNumbersAsync()
{
for (int i = 0; i < 10; i++)
{
await Task.Delay(100);
yield return i;
}
}