Compare List<T>

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I need to prefome a sync process on two Lists
Lets say i have two Lists of type string.
And each list can be dimensioned differently, but will eventually
contain the same amount of elements at some point.
Each list has a default element that must always remain these will
always be different form each other.
And one List will always be the master and all others lists will
ether add or subtract to from the master list to them self's.

What is the best way to go about matching the child list to the parent.
When they become different.

Lets say List A is the master
List<string> listA = new List<string>({"Red", "Green", "Blue", "Yellow"});

// List B can never contain element "Yellow" so we will remove
listA.Remove("Yellow");

// List B will always contain element "Black"
// remove all other elements form ListB that are not in
// List A
List<string> listB = new List<string>({"Red", "Green", "Blue", "White",
"Purple", "Orange", "Black"});


Thank you very much for your response.
Ron
 
Ron said:
I need to prefome a sync process on two Lists
Lets say i have two Lists of type string.
And each list can be dimensioned differently, but will eventually
contain the same amount of elements at some point.
Each list has a default element that must always remain these will
always be different form each other.
And one List will always be the master and all others lists will
ether add or subtract to from the master list to them self's.

What is the best way to go about matching the child list to the parent.
When they become different.

Lets say List A is the master
List<string> listA = new List<string>({"Red", "Green", "Blue", "Yellow"});

// List B can never contain element "Yellow" so we will remove
listA.Remove("Yellow");

// List B will always contain element "Black"
// remove all other elements form ListB that are not in
// List A
List<string> listB = new List<string>({"Red", "Green", "Blue", "White",
"Purple", "Orange", "Black"});

That would depend on the sizes, life cycles, differentness and
ordering requirements of your lists. Is there a canonical ordering
that is always respected, or will the lists have different orderings?
Do the lists change in response to user actions, external data, or
fixed rules? How large are the lists, how many of them are there,
and how different will they be from the master list? And why
remove "Yellow" from A because B can't have it?

(Reminds me... I once knew a little girl with a temper. For
a while, she wore braces to correct her teeth. She couldn't
have chewing gum, and for that reason, her brothers were
deprived of same, because the sight of it would give their
sister a bad misfit... will B get a misfit if it sees a "Yellow"
in A?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top