gpt4 book ai didi

c# - 如何返回异步 IEnumerable

转载 作者:行者123 更新时间:2023-12-04 14:40:54 24 4
gpt4 key购买 nike

我有以下方法:

public async IEnumerable<string> GetListDriversAsync()
{
var drives = await graphClient.Drive.Root.Children.Request().GetAsync();
foreach (var d in drives)
yield return d.ToString();
}

但是编译器错误说:

"The return type of an async must be void, Task or Task <T>"



当方法为异步时如何返回 IEnumerable?

最佳答案

尝试这个:

public async Task<IEnumerable<string>> GetListDriversAsync()
{
var drives = await graphClient.Drive.Root.Children.Request().GetAsync();

IEnumerable<string> GetListDrivers()
{
foreach (var d in drives)
yield return d.ToString();
}

return GetListDrivers();
}

关于c# - 如何返回异步 IEnumerable<string>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56022610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com