473,320 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Custom Collection

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
1 851

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anthony Bouch | last post by:
Hi I've been reading using the XmlSerializer with custom collections. I've discovered that when serializing a custom collection (a class that implements ICollection, IList etc.) the...
0
by: panik | last post by:
Hi, I have a custom collection that implements CollectionBase. The collection is called Sensors and contains a list of Sensor objects. There is the usual index using an integer (Sensors). ...
8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
1
by: Jeff S | last post by:
I'm storing a list of widgets in a database. The list changes infrequently (twice per week at most), and is relatively short (200 items at most, with very little detail per item). A small subset of...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
4
by: Stuart | last post by:
I hope someone can shed some light on an error I've been experiencing for sometime now, but can no longer continue to ignore :-( I've created a custom entity class which implements IEditableObject....
7
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int,...
0
by: Pieter | last post by:
Hi, I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from BindingList(Of T) ) for all my lists. The NHibernate documentation told me that I had to implement...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.