title: Creating a collection object
body: <blockquote>
    <p>Not a homework question, despite the bizarreness of the scenario. I've just substituted the real objects I'm working with to simplify the examples.</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/558304/can-anyone-explain-ienumerable-and-ienumerator-to-me">This</a> has got me started here, but unsure how to proceed. I'm trying to write a class that contains a collection, and I'm getting lost in the world of <code>IEnumerator</code> and <code>IEnumerable</code>, which I'm very new to (and not even entirely sure I'm on the right path). Let's say I have a class:</p>
  
  <pre><code>Public Class BakedBean
      Private Shape As String
      Private Variety As String
      Private Flavour As String
      'etc
  End Class
  </code></pre>
  
  <p>And another class to represent a collection of <code>BakedBean</code>s:</p>
  
  <pre><code>Public Class TinOfBeans
      '?
  End Class
  </code></pre>
  
  <p>I want to be able to get <code>Beans</code> in the <code>TinOfBeans</code> class as a collection, so that I can make calls like these, but without being tied to a specific collection type:</p>
  
  <pre><code>Dim myTin As New TinOfBeans()
  myTin.Add(New BakedBean(...))
  
  For Each bean As BakedBean in myTin
      '...
  Next
  
  myTin(0).Flavour = "beany"
  </code></pre>
  
  <hr>
  
  <p>I've been looking at <code>IEnumerable</code> and <code>IEnumerator</code>, and I have this much so far, but I'm getting <em>very</em> lost with it:</p>
  
  <p><strong>BakedBean Class</strong></p>
  
  <pre><code>Public Class BakedBean
      Private Shape As String
      Private Variety As String
      Private Flavour As String
      'etc
  End Class
  </code></pre>
  
  <p><strong>BeansEnumerator Class</strong></p>
  
  <pre><code>Public Class BeansEnumerator
      Implements IEnumerator
  
      Private Position As Integer = -1
  
      Public ReadOnly Property Current As Object Implements System.Collections.IEnumerator.Current
          Get
              '???
          End Get
      End Property
  
      Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
          '???
      End Function
  
      Public Sub Reset() Implements System.Collections.IEnumerator.Reset
          Position = -1
      End Sub
  End Class
  </code></pre>
  
  <p><strong>TinOfBeans Class</strong></p>
  
  <pre><code>Public Class TinOfBeans
      Implements IEnumerable
  
      Private beansEnum As BeansEnumerator
  
      Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
              Return beansEnum
      End Function
  End Class
  </code></pre>
  
  <p>At this point I'm getting rather tied up in knots and have no idea how to proceed (or, as I said at the start, if this is even the right approach). Any suggestions?</p>