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("Hell o")
oList.Add("worl d")
Dim oEnum As List(Of String).Enumera tor = oList.GetEnumer ator()
While oEnum.MoveNext( )
Dim sValue As String = oEnum.Current
End While
CType(oEnum, IEnumerator).Re set()
While oEnum.MoveNext( )
Dim sValue As String = oEnum.Current
End While
Anyone know what I am doing wrong? 2 5135
"wvtempl" <wv*****@discus sions.microsoft .com> wrote in message
news:DF******** *************** ***********@mic rosoft.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("Hell o") oList.Add("worl d") Dim oEnum As List(Of String).Enumera tor = oList.GetEnumer ator() While oEnum.MoveNext( ) Dim sValue As String = oEnum.Current End While CType(oEnum, IEnumerator).Re set()
Try oEnum = oList.GetEnumer ator() 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?
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*****@discus sions.microsoft .com> wrote in message news:DF******** *************** ***********@mic rosoft.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("Hell o") oList.Add("worl d") Dim oEnum As List(Of String).Enumera tor = oList.GetEnumer ator() While oEnum.MoveNext( ) Dim sValue As String = oEnum.Current End While CType(oEnum, IEnumerator).Re set() Try oEnum = oList.GetEnumer ator() 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? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 state field in the collection, and every
time something is inserted or deleted from the collection, I will just
change the guid. Enumerator will just have to compare the guid received in
the begging to the current one. If they are different, the...
|
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
bool IEnumerator.MoveNext() an
void IEnumerator.Reset()
The help to IEnumerator.MoveNext describes that "after the end of the collection is passed, subsequent calls to MoverNect return false until reset is called"
When, however, I have two...
|
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 stop once the value of 10
is reached. My question, is what's the real point of implemending the
Reset() method, if it is never used by foreach statement. Of course, it
gives me some allocated place where I can do some "enumerator resetting" and...
|
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
|
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 property "Current". The challange is
that I need to implement two versions of the property: one of type
System::Object as required by Collections::IEnumerator, the other of type T^
as required by Collections::Generic::IEnumerator<T>
...
| |
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 via the
GetEnumerator method would be synchronized with the collction; if the
collection changes, the existing enumerators are notified via an event.
The accompanying EventArgs derived class object carries information
about the change to the...
|
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 IEnumerator<stringGetEnumerator() {
|
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 interface. Please help me resolve the error
I was able to implement the non Generics version
|
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, because GetEnumerator always returns a new one.
My proposal would allow the following scenario:
You could for example the first and the last element of the list as a
special case:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |