By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,043 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,043 IT Pros & Developers. It's quick & easy.

Custom Collection

P: n/a
I'm trying to create a custom collection for educational purposes only for now.

I want to implement the IEnumerable interface but don't know what I'm doing with
it. How to I create/get/return the expected value for the implemented
GetEnumerator() function? I know the value expected is an IEnumerator, but what
is it? Basically, I would like a nice, clean example to follow and learn from.

Thanks :)

Haven't had much time to do any "real" searches for it on Google...trying here
first as a quick-start...hopefully t'is all I need.

Mythran
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Mythran" <ki********@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP10.phx.gbl...
I'm trying to create a custom collection for educational purposes only for now.

I want to implement the IEnumerable interface but don't know what I'm doing with it. How to I create/get/return the expected value for the implemented
GetEnumerator() function? I know the value expected is an IEnumerator, but what is it? Basically, I would like a nice, clean example to follow and learn from.

Thanks :)

Haven't had much time to do any "real" searches for it on Google...trying here
first as a quick-start...hopefully t'is all I need.

Mythran


I think I figured it out....

Public Class MyCollectionEnumerator
Implements IEnumerator

#Region " Private Members "
' ================================================== ========================
' Private Members
' ================================================== ========================
Private mItems As MyItem() = Nothing
Private mIndex As Integer = -1
#End Region

#Region " Public Constructors / Destructors "
' ================================================== ========================
' Public Constructors / Destructors
' ================================================== ========================
Public Sub New(ByVal Items As MyItem())
mItems = Items
End Sub
#End Region

#Region " Public Properties "
' ================================================== ========================
' Public Properties
' ================================================== ========================
Public ReadOnly Property Current() As Object Implements
System.Collections.IEnumerator.Current
Get
Return mItems(mIndex)
End Get
End Property
#End Region

#Region " Public Methods "
' ================================================== ========================
' Public Methods
' ================================================== ========================
Public Function MoveNext() As Boolean Implements
System.Collections.IEnumerator.MoveNext
mIndex += 1
Return (mIndex > mItems.Length OrElse Not mItems(mIndex) Is Nothing)
End Function

Public Sub Reset() Implements System.Collections.IEnumerator.Reset
mIndex = -1
End Sub
#End Region
End Class
It works :) ANything anyone sees as being wrong?

Mythran
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.