c# - 为什么 IAsyncEnumerator 在 C#8 中没有 Reset 方法?

标签 c# async-await c#-8.0

为什么 IAsyncEnumerator 没有 Reset 方法?它只有 Current 属性和 MoveNextAsync() 方法。

public interface IAsyncEnumerator<out T> : IAsyncDisposable
{
    T Current
    {
        get;
    }

    ValueTask<bool> MoveNextAsync();
}

最佳答案

来自 IEnumerator.Reset 的文档:

The Reset method is provided for COM interoperability. It does not necessarily need to be implemented; instead, the implementer can simply throw a NotSupportedException.

很少有 Reset 方法除了抛出异常之外还能做任何事。所有 Linq 类型都会抛出异常(例如 here ),编译器生成的 IEnumerators 也会抛出异常(参见 here )。

假设 IAsyncEnumerator 永远不会与 COM 互操作,并且假设不会有任何 C# 代码依赖于能够Reset 一个IEnumerator,为什么要为 IAsyncEnumerator 添加一个类似的方法,它同样总是通过抛出异常来实现?

关于c# - 为什么 IAsyncEnumerator 在 C#8 中没有 Reset 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55663481/

相关文章:

c# - MediaPlugin - 从路径获取媒体文件

c# - 异步/等待执行差异

c# - 事件实例字段成员可以为空吗(假设它没有被强制设置为空)?

c# - 具有默认实现的接口(interface)和抽象类之间有什么区别?

c# - Linq 中的 IF else 语句

c# - Discord 在我的 GitHub 上编译的 dll 中找到了机器人 token

javascript - 如何与 Puppeteer/Javascript 同时运行脚本?

dependency-injection - 某些服务无法使用库 : NetCore. AutoRegisterDi 构建

c# - 使用 dataSet.GetXml() 获取内存

c# - 具有 CancellationTokenSource 的 channel 在处理后出现超时内存泄漏