Compare two lists

  • 12 years ago

     What i want to do is compare two lists, and then view which items have been added/removed.

    So, for example:

    List1:

    bob
    jack
    tim
    dave
    john

    Compared with list2:

    bob
    alan
    jack
    tim
    george
    john

    would show that alan and george were added and that dave was removed.

    How would i go about this? 

  • 12 years ago

    I believe by now you would already have solved your problem. If no, here is what you can do:

    1. Overload subtraction operator (or write a function Difference) that takes two lists List1 and List 2 as parameters and returns a list of
    all members of List1 that are not in List2.

    2. With this List1 - List2 (or Difference(List1, List2)) will give you all items removed and List2 - List1 (or Difference(List2, List1) will
    give all items added to go from List1 to List2.
     

    Hope I understood your problem correctly and that this solution helps.

     
    Asad 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.” - Dan Kaminsky