JRockFL
asked on
Iterate two lists and remove inactive
I need to iterate two lists and remove inactive or create a new list with just active.
It is a parent/child relation.
IList<string> activeIDs; this contains the list of active ids.
If the id in ClassificationDetail matches, then include this in the list.
It is a parent/child relation.
IList<string> activeIDs; this contains the list of active ids.
If the id in ClassificationDetail matches, then include this in the list.
public class Classification
{
public List<Classification> Children { get; set; }
public ClassificationDetail Classification { get; set; }
}
public class ClassificationDetail
{
string id {get; set;}
}
IList<Classification>
ASKER
Thank you for the reply. Will this take into consideration the parent child relationships?
I need to traverse list.
I need to traverse list.
From what I see - the answer to your question is "No".
It seems the task might be a bit tricky. And I'd like to clarify it - the question is not clear..
As I understand every Classification object contains a list of "child" Classification objects. Therefore, in it's turn, every child classification may have it's own children? Yes or no? And every "grandchild" may have own children as well? How deep this can be?
The second question is: what Classification objects do we select for your "selected" list? Only "parent" Classification objects that have active IDs or at least one of its children/grandchildren/gra ndgrandchi ldren/... has active IDs? Or children/grandchildren/gra ndgrandchi ldren themselves?
Will try to explain on an example.
. Scenario 1.
Parent CP1 has children CC1,CC2,CC3
CP1 is actice, and CC2 is active.
What classifications do you include into the list? CP1 only? Or CP1 and CC2?
. Scenario 1.
Parent CP1 has children CC1,CC2,CC3
CP1 is inactice, only CC2 is active.
What classifications do you include into the list? CP1? Or CC2?
You may have more scenarios with grandchildren, etc.
It seems the task might be a bit tricky. And I'd like to clarify it - the question is not clear..
As I understand every Classification object contains a list of "child" Classification objects. Therefore, in it's turn, every child classification may have it's own children? Yes or no? And every "grandchild" may have own children as well? How deep this can be?
The second question is: what Classification objects do we select for your "selected" list? Only "parent" Classification objects that have active IDs or at least one of its children/grandchildren/gra
Will try to explain on an example.
. Scenario 1.
Parent CP1 has children CC1,CC2,CC3
CP1 is actice, and CC2 is active.
What classifications do you include into the list? CP1 only? Or CP1 and CC2?
. Scenario 1.
Parent CP1 has children CC1,CC2,CC3
CP1 is inactice, only CC2 is active.
What classifications do you include into the list? CP1? Or CC2?
You may have more scenarios with grandchildren, etc.
ASKER
Yes, that is correct. There is a root object that contains 48 children. Each of those child may or not have children and it can go indefinitely.
The classificationdetail object has a property called Id. If that Id matches one of the ids in the "active" list. Then it is considered active.
CP1 and CC2 would each have an "active" id in the list.
The classificationdetail object has a property called Id. If that Id matches one of the ids in the "active" list. Then it is considered active.
CP1 and CC2 would each have an "active" id in the list.
Sorry, I called both scenarios "Scenario1" :). For the second one, what objects do we include to the "selected" list? Do we consider CP1 active if it has NOT active ID but one of his children/grandchildren/... has active ID?
outcome 1: We include both CP1 into "final" list because it has "active" children + CC2 as it has active ID
outcome 2: We include only"active" child CC2 as it has active ID
outcome 1: We include both CP1 into "final" list because it has "active" children + CC2 as it has active ID
outcome 2: We include only"active" child CC2 as it has active ID
ASKER
That scenario should never happen.
It would be much easier if you explain the problem clearly :).
OK, another question about the Scenario1.
What do we include into the final list? CP1 and CC2? Or only CP1?
What is our "starting point"?
I know that we have IList<string> activeIDs. This is clear.
What about Classification? You have just one Classification object with children? Or you have a collection of classifications, aka "parents"?
One can't get a solution if requirements are not clear!..
OK, another question about the Scenario1.
What do we include into the final list? CP1 and CC2? Or only CP1?
What is our "starting point"?
I know that we have IList<string> activeIDs. This is clear.
What about Classification? You have just one Classification object with children? Or you have a collection of classifications, aka "parents"?
One can't get a solution if requirements are not clear!..
ASKER
We start off with a collection of Classification
IList<Classification> with a count of 1
This root ojbect has 49 children.
Some of these children have children.
So of these children do not have children.
And this continues with their children.
Then we ClassificationDetail classs. Specifically, the id.
If that id is in our active list. Then this is active.
IList<Classification> with a count of 1
This root ojbect has 49 children.
Some of these children have children.
So of these children do not have children.
And this continues with their children.
Then we ClassificationDetail classs. Specifically, the id.
If that id is in our active list. Then this is active.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. I will review tomorrow
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window