473,811 Members | 3,737 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 1628
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.Remo ve(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
6581
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
2236
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 -- comments welcome! "Intro to loops" <url: http://home.no.net/dubjai/win32cpptut/w32cpptut_01_03.doc> As before I expect that here's mental food and technical points that we can strongly disagree about, for both newbie and the experienced.
10
2036
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
1167
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 of multi-line “book records”, separated by blank rows. The number of rows in each “book record” varies, as in this diagram: 1xxxxxx xxxxxx TitleRow
6
2893
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 it. Is there a way to prevent this dialog box to show up? I'm writing a script used only on a intranet and the final customer should not see the message box.
17
3063
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 counter within the loop declaration, for loops have always seemed to me to be about doing something a certain number of times, and not about iterating over an object. The reason for this distinction comes from the fact that I read a lot how...
1
1566
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 I'm simulating the functionality of the DetailsView or a GridView cell, except that my data is dynamic (variable number of fields), so I can't just use those. So I have custom edit and view controls for this dynamic data and I render one of...
25
2266
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 more restrictive filters so that only the desired items can fall all the way through. This method is so obvious and common it must have a name. What is it or at least, what is the best (short) way to describe it? For Each In If Then If Then
14
8022
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 error states: X2 Provider Error: <ExecuteHelper Failed> X2 Provider Error: <Internal Error: Failed to get the IProc Interface> The provider works with ADO.Net according to the developer.
0
9731
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10651
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, 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...
0
10393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
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,...
0
10136
tracyyun
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...
1
7671
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5556
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...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3020
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 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...

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.