Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have wrote a a thread safe collection inherited from IList(OF T) and and also wrote an Enumerator Inherited from IEnumerator(Of T), the below code shows the GetEnumerator Method

VB
Public Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
    Dim value As IEnumerator(Of T) = CType(Nothing, IEnumerator(Of T))
    SyncLock Me._lock
        ' Why My collection not respect my Enumerator.......??????????????
        value = New RiverNileListEnumerator(Me)

    End SyncLock
    Return value
End Function


During testing the collection, found that it returns No values but when I did replace My-Enumerator with the InnerList (List(Of T) Enumerator the collection will works fine with For Each Statement.

VB
' the collection works fine with this value
          value = Me.InnerList.GetEnumerator()


any advice will be appreciated. Thanks
Posted
Comments
phil.o 23-May-14 1:17am    
You wrote an article three years ago about implementing an enumerator:

Implementation of IEnumerable(of T) & IEnumerator(Of T) in VB.NET

And now this very basic question about it?
There is something I'm just missing...

1 solution

I get the answer, i shall use for each statement like this

VB
For Each obj As object In objects.ToArray()
       foo.Items.Add(obj)
   Next
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900