为什么 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/