IEnumerable and IEnumerator in the same class, bad idea?

It is a bad idea?

Private Class GH_DataStructureEnumerator(Of Q As Types.IGH_Goo)
  Implements IEnumerable(Of Q)
  Implements IEnumerator(Of Q)
  ....
  ....
  'Current, MoveNext, Reset etc.'
  ....
  ....

  Public Function GetEnumerator_Generic() As IEnumerator(Of Q) _
                  Implements IEnumerable(Of Q).GetEnumerator
    Return Me
  End Function
End Class

This class is only displayed as the readnly IEnumerable (Of T) property, and it saves me an extra class that wraps IEnumerator (Of T). But somehow it seems wrong. Is there a better way?

+5
source share
3 answers

This is a bad idea because the solution will break if someone tries to list your collection several times at the same time.

For example: it will somehow break

For Each cur1 in yourObj 
  For Each cur2 in yourObj
    Console.WriteLine("{0} - {1}", cur1,cur2)
  Next
Next
+4
source

. , , GetEnumerator - .

, , # , , ... , , . :)

+5

IEnumerable:

GetEnumerator(), , "Enumerator".

, - .

+1

All Articles