Implementing IList

D

Don

I have a class which contains a collection of objects that I want to be able
to bind to things like Combobox controls. As I understand it, I would need
to implement the IList interface to be able to do this.

I am having trouble implementing the GetEnumerator() method. From what I
could gather on the few articles I could find online, it would appear that
this method has to return an instance of a class that implements
IEnumerator. Is this correct? If so, is it proper to do the following
(cutting out lots of implementation code):

Public Class MyList
Implements IList

...

Public Function GetEnumerator() As System.Collections.IEnumerator _
Implements System.Collections.IEnumerable.GetEnumerator

Return New MyListEnum(Me)

End Function

...

End Class

Public Class MyListEnum
Implements Enumerable

Private _List as MyList

Public Sub New(ByVal theList as MyList)
_List = theList
End Sub

<...implement methods for enumerating the _List object here...>

End Class

? Or am I missing the point entirely?


- Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top