IEnumerator:Dispose 方法为空是否正常?

发布于 2024-09-05 21:30:37 字数 632 浏览 2 评论 0原文

我正在编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光礼记 2024-09-12 21:30:37

是的。

IEnumerator 实现 IDisposable,以防您创建确实需要处置的枚举器。由于大多数枚举器不需要被释放,因此该方法通常为空。

顺便说一句,您可以通过 创建迭代器

Yes, it is.

IEnumerator<T> implements IDisposable 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文