IEnumerator:Dispose 方法为空是否正常?
我正在编写一个 IEnumerator
用于迭代 COM 集合的类 我是 包装。我注意到 IEnumerator
扩展了 IDisposable
,因此我需要实现 Dispose
方法。
但是,我想不出要放在那里的任何内容,因为我只有对集合的引用(我不希望在 foreach
的末尾处理它)和 < code>int 为索引。将 Dispose
方法留空是否正常?
I'm writing an IEnumerator<T>
class to iterate over a COM collection I'm wrappering. I've noticed that IEnumerator<T>
extends IDisposable
, so I'm required to implement the Dispose
method.
However, I can't think of anything I would put there, as I only have a reference to the collection (which I wouldn't want being disposed at the end of a foreach
), and an int
for the index. Is it normal to leave the Dispose
method empty?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
IEnumerator
实现IDisposable
,以防您创建确实需要处置的枚举器。由于大多数枚举器不需要被释放,因此该方法通常为空。顺便说一句,您可以通过 创建迭代器。
Yes, it is.
IEnumerator<T>
implementsIDisposable
in case you make an enumerator that does need to be disposed. Since most enumerators don't need to be disposed, the method will usually be empty.By the way, you can implement your
IEnumerator
more easily by creating an iterator.