IEnumerator:具有空的Dispose方法是否正常? [英] IEnumerator: Is it normal to have an empty Dispose method?
问题描述
我正在编写一个 IEnumerator<T>
类进行迭代一个 COM 集合,我是 IDisposable
,所以我需要实现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.
但是,我想不出要放在那里的任何东西,因为我只引用了该集合(我不想将其放置在int
用于索引.将Dispose
方法保留为空是否正常?
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?
推荐答案
是的.
IEnumerator<T>
实现IDisposable
,以防您制作确实需要处理的枚举数.由于不需要处理大多数枚举数,因此该方法通常为空.
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.
通过创建一个迭代器.
这篇关于IEnumerator:具有空的Dispose方法是否正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!