Create empty IAsyncEnumerable

后端 未结 2 754
夕颜
夕颜 2021-01-03 18:23

I have an interface which is written like this:

public interface IItemRetriever
{
    public IAsyncEnumerable

        
2条回答
  •  一生所求
    2021-01-03 19:11

    If you install the System.Linq.Async package, you should be able to use AsyncEnumable.Empty(). Here's a complete example:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    
    class Program
    {
        static async Task Main()
        {
            IAsyncEnumerable empty = AsyncEnumerable.Empty();
            var count = await empty.CountAsync();
            Console.WriteLine(count); // Prints 0
        }
    }
    

提交回复
热议问题