473,322 Members | 1,504 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,322 software developers and data experts.

How to use IEnumerator.Reset with generic collection in VB.NET

From the documentation in MSDN, it looks as though the following should
iterate through the collection twice. However, MoveNext in the second
iteration returns false:
Dim oList As New List(Of String)
oList.Add("Hello")
oList.Add("world")
Dim oEnum As List(Of String).Enumerator = oList.GetEnumerator()
While oEnum.MoveNext()
Dim sValue As String = oEnum.Current
End While
CType(oEnum, IEnumerator).Reset()
While oEnum.MoveNext()
Dim sValue As String = oEnum.Current
End While
Anyone know what I am doing wrong?
May 4 '06 #1
2 5100
"wvtempl" <wv*****@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com...
From the documentation in MSDN, it looks as though the following should
iterate through the collection twice. However, MoveNext in the second
iteration returns false:
Dim oList As New List(Of String)
oList.Add("Hello")
oList.Add("world")
Dim oEnum As List(Of String).Enumerator = oList.GetEnumerator()
While oEnum.MoveNext()
Dim sValue As String = oEnum.Current
End While
CType(oEnum, IEnumerator).Reset() Try oEnum = oList.GetEnumerator() instead to start over with a brand new
enumerator.
Or just use For Each and let the compiler take care of the enumerators. While oEnum.MoveNext()
Dim sValue As String = oEnum.Current
End While
Anyone know what I am doing wrong?

May 4 '06 #2
Thanks, getting a new enumerator is the workaround I have been using. Does
anyone know if the Reset method simply doesn't work, or if the way I am
calling it is incorrect?

"Ben Voigt" wrote:
"wvtempl" <wv*****@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com...
From the documentation in MSDN, it looks as though the following should
iterate through the collection twice. However, MoveNext in the second
iteration returns false:
Dim oList As New List(Of String)
oList.Add("Hello")
oList.Add("world")
Dim oEnum As List(Of String).Enumerator = oList.GetEnumerator()
While oEnum.MoveNext()
Dim sValue As String = oEnum.Current
End While
CType(oEnum, IEnumerator).Reset()

Try oEnum = oList.GetEnumerator() instead to start over with a brand new
enumerator.
Or just use For Each and let the compiler take care of the enumerators.
While oEnum.MoveNext()
Dim sValue As String = oEnum.Current
End While
Anyone know what I am doing wrong?


May 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Sasha | last post by:
Hi, I am extending standard IEnumerator, and I was just wondering what is the best way to make enumarator safe? What do I mean by safe? Detect deletes and all... My idea is to have private Guid...
3
by: Hans | last post by:
I implemented the IEnumerator interface in some classes to enable the use of the foreach statement. As you probalbly know, the interface asks for the implementation of object IEnumerator.Curren...
2
by: Pavils Jurjans | last post by:
Hello, please consider the code at the end of this posting, that depicts simple case of custom enumerator. This particular example will enumerate over list of random number within 1..10, and will...
3
by: starter | last post by:
I am trying to learn IEnumerator and collections(ArrayList, Hashtable) in .NET. Can anyone tell me what is IEnumerator used for and any online resources would be helpful. Thanks
1
by: midnight madness | last post by:
I tried but failed to implement a template class that support IEnumerator<T> interface using C++/CLI in VS 2005 Professional version. I could not figure out the proper syntax to implement the...
11
by: Leslie Sanford | last post by:
I've been kicking around an idea mostly as a thought experiment at this point. The idea is to create a thread safe collection that implements the IEnumerable interface. The enumerators it creates...
3
by: rossum | last post by:
I have been trying to get the IEnumerable interface to compile, and am having some difficulties. When I try to compile: class TestIEnum : IEnumerable<string{ string theStrings; public...
5
by: Shikari Shambu | last post by:
Hi, I am trying to implement a collection that implements IEnumerable<T>. I keep getting the following error 'IEnumerator<...>.Current' in explicit interface declaration is not a member of...
3
by: cody | last post by:
Currently it is only legal to use types which has a method named GetEnumerator to be used in a foreach loop. This makes it impossible to use the same Enumerator after and before a foreach loop,...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.