PC Review


Reply
Thread Tools Rate Thread

Custom Collection

 
 
Mythran
Guest
Posts: n/a
 
      24th May 2004
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


 
Reply With Quote
 
 
 
 
Mythran
Guest
Posts: n/a
 
      24th May 2004

"Mythran" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a collection of custom classes in another custom class kagard Microsoft Access 3 12th Jun 2011 07:57 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
DataGridView - Custom Collection - Remove New Row from Collection =?Utf-8?B?V2ViYmVydA==?= Microsoft Dot NET 0 8th Sep 2006 12:09 PM
Can't get collection to save when using collection of custom class as property of control in VS 2005 J.Edwards Microsoft Dot NET Compact Framework 0 10th Jan 2006 04:44 AM
Custom collection: how to find item in collection using custom indexer panik Microsoft C# .NET 0 21st Aug 2003 09:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:51 AM.