473,503 Members | 8,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Interleaving loops on the same collection

52 New Member
Hi,

I wann use the same collection in interleaving loops.
like
F1(..)
{
foreach(child prd in parent)
F2(prd )
}

F2(..)
{
foreach(child p in parent)
{
// which manipulate 'parent' collection by deleting an element here..
// This creats problem in F1 as the same collection is under use..
}

Any links/eg to handle this problem is greatly appreciated.
}
Feb 6 '08 #1
5 1603
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Could you please describe your question more?

Are you trying to look for a way to shorten code by reusing code?
Feb 6 '08 #2
sudhivns
52 New Member
Yes intention behind it is code reuse:

Delete(..)
{
foreach (X x in Collection )
{
if(...)
DelNow(x)
}
}

DelNow(.. prd.. )
{

foreach(X a in Collection)
{
if(....)
{ del = true; break;}
}

Collection.Remove(prd)

}

Here DelNow() manipulates the Collection object, which is already under looping in function Delete(). Idea here is to reuse the DelNow() call in Delete() but under a looping of Collection Object. Hope this is clear now.
Feb 6 '08 #3
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Can you make a seperate method passing the collecrtion as a parameter
Feb 6 '08 #4
r035198x
13,262 MVP
If you are going to be deleting items from a collection that you are looping over then be careful that you won't run yourself into concurrent modification ...
Feb 6 '08 #5
sudhivns
52 New Member
I do not want to disturb DelNow() function either body or signature.
Only i can modify the Delete() function
Feb 6 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

15
6555
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
13
2202
by: Alf P. Steinbach | last post by:
The third part of my attempted Correct C++ tutorial is now available, although for now only in Word format (use free Open Office if no Word), and also, it's not yet been extensively reviewed -- ...
10
2016
by: Roshawn | last post by:
Hi, I am experimenting with nested For...Next loops. My code looks like this: Dim i as Byte Dim itm as Byte For i = 0 to 9 For itm = 0 to 9 'code omitted
3
1155
by: GeorgeAtkins | last post by:
Using VB.NET in VS 2003. This should be a simple routine, but it has me flummoxed. I have to compare strings in two text files: FILE1(srar) consists of lines of book titles. FILE (srac) consists...
6
2878
by: Fabian Vilers | last post by:
Hi all, I'm my script I've three loops processing a very huge data file. IE & Firefox show a message box after some time saying my script could be infinite looping and give me a chance to stop...
17
3031
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
1
1538
by: estebistec | last post by:
Hello, I've developed a CompositeControl in C# for ASP.NET 2.0. In this control I am simulating Edit and View modes by hiding or showing appropriate controls (setting Control.Visible). Basically...
25
2189
by: GY2 | last post by:
I writing some documentation and I want to describe a common code structure which is used to step through all the items in a collection (e.g. each file in a subdirectory) while applying more and...
14
7961
by: johndonnelly | last post by:
HI, I am trying to figure out how to write a C# program to add parameter's "A" and "B" and return "C" in the following code: I get an error at the commnd.ExecuteNonQuery(); statement below. The...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
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...
0
7291
Oralloy
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,...
1
7012
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...
0
5598
agi2029
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,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3180
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...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
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...

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.