Given I\'ve written a class that implements IEnumerable
, and returns an IEnumerator
that\'s not just IDisposable
by nature of being an
Yes, you can rely on the call of Dispose()
on your iterators from inside the methods of LINQ.
In the reference code published by Microsoft, the use of iterators falls in three categories:
foreach
loop, which ensures a call of Dispose()
, orwhile
loop; these iterators are disposed explicitlyusing
block, which ensures automatic disposal.In all these cases the library ensures that iterator's Dispose()
method is called upon completion.