D
Doug
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<PossibleDups> dups"
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<PossibleDups> dups)
{
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?
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<PossibleDups> dups"
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<PossibleDups> dups)
{
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?