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

Enumerating and removing

Hello all,

I have written the following code that both enumerates and also removes from
the collection being enumerated. As the code illustrates, this causes me to
have to reset the enumerator. Clearly this isn't very attractive.

Dim enumerator As IEnumerator = _containmentTree.GetEnumerator
While (enumerator.MoveNext)
Dim classProxy As G2ProxyBase = CType(enumerator.Current, G2ProxyBase)
Dim proxyName As String = classProxy.Name
If Not _topLevelAssets.Contains(proxyName) Then
_containmentTree.Remove(classProxy)
enumerator = _containmentTree.GetEnumerator
End If
End While

I'm sure there is a better way, but I haven't thought of it yet. What do you
others think?

Nov 22 '05 #1
1 1219
Use of "for" loop and start at the highest element. Move downward as you
go. Then just remove what your index is at. Then just continue downward.
No messing with enumerators.

"Kevin in Chicago" <Kevin in Ch*****@discussions.microsoft.com> wrote in
message news:95**********************************@microsof t.com...
Hello all,

I have written the following code that both enumerates and also removes
from
the collection being enumerated. As the code illustrates, this causes me
to
have to reset the enumerator. Clearly this isn't very attractive.

Dim enumerator As IEnumerator = _containmentTree.GetEnumerator
While (enumerator.MoveNext)
Dim classProxy As G2ProxyBase = CType(enumerator.Current, G2ProxyBase)
Dim proxyName As String = classProxy.Name
If Not _topLevelAssets.Contains(proxyName) Then
_containmentTree.Remove(classProxy)
enumerator = _containmentTree.GetEnumerator
End If
End While

I'm sure there is a better way, but I haven't thought of it yet. What do
you
others think?

Nov 22 '05 #2

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

Similar topics

0
by: Brett Mostert | last post by:
Hi, I need to be able to Enumerate through Printer Drivers, ports, printers and so fourth. And even add printers, ports, and drivers and setup printers. Sofar i can do all of the following...
2
by: Bishman | last post by:
Can anyone suggest a method of enumerating instances of MSDE 2000 without using DMO ? Using C++, MFC, and ADO. Thanks
4
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
1
by: Kevin | last post by:
Hi, How can I enumerate a linked list while being hable to delete any number of elements while enumerating ? I was using: struct st { ... struct st *prev;
0
by: Michael C | last post by:
Hi all, After a lot of research, I've come to some realizations about enumerating Named Instances of MSDE. NetServerEnum() Win32 API function doesn't work, SQL-DMO doesn't work, no standard...
4
by: Brett Mostert | last post by:
Hi, I need to be able to Enumerate through Printer Drivers, ports, printers and so fourth. And even add printers, ports, and drivers and setup printers. Sofar i can do all of the following...
2
by: Tony | last post by:
I have this problem - I have a hashtable, containing a list of filenames. Every 60 seconds, I have a thread that enumerates thru this hashtable, and based on some simple logic, some of the items...
1
by: Glenn Leifheit | last post by:
Does anyone have any sample code on enumerating network shares with vb.net. I here you need to use wither an API or WMI, or are there other recomendations. Thanks Glenn
1
by: Shelby | last post by:
Hi, I would like to modify the object's value while enumerating but I get this error Additional information: Collection was modified; enumeration operation may not execute. This is my code: ...
10
by: pamelafluente | last post by:
Hi I have a sorted list with several thousands items. In my case, but this is not important, objects are stored only in Keys, Values are all Nothing. Several of the stored objects (might be a...
1
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.