【发布时间】:2019-11-14 18:03:08
【问题描述】:
在 MethodB 的返回签名是 IAsyncEnumerable 的情况下,并且它是从 MethodA 内部调用的,是否可以返回一个 IAsyncEnumerable,而无需迭代 MethodB 的返回值,如下所示:
IAsyncEnumerable<T> MethodB() => do stuff;
IAsyncEnumerable<T> MethodA() => return MethodB(); <- this gives a compiler error: must use yield return;
根据错误消息,我认为唯一的方法如下:
async IAsyncEnumerable<T> MethodA() => await foreach(var t in MethodB())yield return t;
【问题讨论】:
标签: c#