编译器错误 CS8411
异步 foreach 语句无法对类型“type”的变量进行操作,因为“type”不包含适合“GetAsyncEnumerator”的公共实例定义
await foreach
语句仅对定义为 GetAsyncEnumerator
的类型(例如 IAsyncEnumerable<T>
)起作用。
更正此错误
将 await foreach
替换为 foreach
。
示例
using System.Collections.Generic;
using System.Threading.Tasks;
class Program
{
async Task Example(IAsyncEnumerator<int> enumerator)
{
// error CS8411: Asynchronous foreach statement cannot operate on variables
// of type 'IAsyncEnumerator<T>' because 'IAsyncEnumerator<T>' does not
// contain a suitable public instance definition for 'GetAsyncEnumerator'
await foreach (int i in enumerator)
{
}
}
}
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈