473,479 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using ForEach and FindAll of Generics

Hi,

I have a collection of objects and I need to compare each item in the
collection to see if it's a match on any or all of the others. I have
stored my collection in an item like so: "List<PossibleDupsdups"
where PossibleDups is an object of my own creation.

I have been looking at how the ForEach and FindAll methods work and
here is what I was thinking might be a good approach to doing this (in
pseudocode):

1. Use the ForEach method to loop through each item in the
collection.
2. Use the FindAll method inside my Action delegate of the ForEach
method to do my comparison.

This would be pretty neat to get it to work like this (very little
code compared to what I had planned). But I think it won't work as I
would have to do something like this:

private void FindActualDuplicates(List<PossibleDupsdups)
{
possibleDuplicates.ForEach(CompareItems);
}

private void CompareItems(PossibleDups dup)
{
bool isDup = possibleDuplicates.FindAll(FindDups);
}

private static bool FindDups(PossibleDups dup)
{
//Code to determine if dups.
}

If you look at my CompareItems method you can see my problem. I don't
have a clear way to get the Array List into that method (even tho I
coded in the method as if I did get it in there) because the ForEach
only sends one item of that list in at a time.

I know that I could bypass the ForEach altogether and do a FindAll
over the entire collection, but I need to do something like this:

1. Compare object 1 in the collection to object 2, 3, 4.
2. Compare object 2 in the collection to object 3, 4.
3. Compare object 3 in the collection to 4.

In essence, if object 1 is a match to just 2. I still need to see if
3 is a match to just 4 (and so on depending on the number of objects
in the collection). Because of this I don't know if I can get away
with not using the ForEach (or using the old foreach method).

Does anyone have any suggestions? Is this possible? Am I
overthinking it?

Jul 19 '07 #1
1 3415
Thank you Nick and Peter, I will look into both your suggestions.
Peter, I think I understood yours (but some of it seemed a bit over my
head :) ) so we'll see how it goes. I'll let you know how it turns
out.

Jul 20 '07 #2

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

Similar topics

13
1968
by: cody | last post by:
foreach does implicitly cast every object in the collection to the specified taget type without warning. Without generics this behaviour had the advantage of less typing for us since casting was...
104
7040
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
14
1783
by: Josh Ferguson | last post by:
I don't believe a syntax driven equivalent exists for this, but I just thought it would be neat if you could use foreach to do something like this: foreach (Object x in collection1, collection2)...
1
5013
by: Derek Martin | last post by:
Hey list, got this code running in a webform: Dim DSESearcher As System.DirectoryServices.DirectorySearcher = New System.DirectoryServices.DirectorySearcher Dim RootDSE As String =...
3
1646
by: Wiktor Zychla [C# MVP] | last post by:
since generics allow us to implement several IEnumerable<T> interfaces on a single class, I think that "foreach" should somehow reflect that. suppose we have a enumerable class class C :...
2
7149
by: sianan | last post by:
I am having a problem doing the following in generics. I have two list of a custom item type. I need to iterate through the first list and match each item against another list to see if there is...
6
4057
by: Mark Rae | last post by:
Hi, I'm in the process of updating an ASP.NET v1.1 web app to v2. The app uses ActiveDirectory a great deal, and I'm trying to use the new System.Collections.Generic namespace where possible,...
5
3106
by: ssg31415926 | last post by:
Does anyone have any experience using SCPs (serviceConnectionPoints) in C#? Specifically, I'm trying to use an SCP to locate a service on a server, once the service has created the SCP. I've...
6
1556
by: Tony | last post by:
Hello! Below I have a complete working program.with some simple classes one of these is a generic class. Now If I want to implement functionallity so I can compare animal with each other or...
0
7027
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,...
1
6719
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
6847
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...
0
5312
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
4757
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
4463
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...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
555
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
166
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.