We have a property definition

Private _join_fields As List(Of ExFieldJoin) = New List(Of ExFieldJoin) 

We also have two instances of this property passed to a function as ByVal With the difference being that in one variable, an old object, and in the second, a new object with a new object in the collection. How to compare these objects and get mismatched elements of the collection?

  • may need Except - Grundy
  • one
    @Grundy: Why not as an answer? - VladD
  • @VladD, because I'm busy for now :) you can redo :) besides, I suspect there will also need some kind of comparator - Grundy
  • @Grundy: I'm generally away :) - VladD
  • var nonintersect = list1.Except (list2) .Union (list2.Except (list1)); - Sergiy

1 answer 1

The answer to the header:

 Var list1 = new List<string>(); //add some data to list1 Var list2 = new List<string>(); //add some data to list2 //разница двух коллекций объектов. Левый внешний var leftOuterJoin = list1.Except(list2).ToList(); //разница двух коллекций объектов. Правый внешний var rightOuterJoin = list2.Except(list1).ToList(); 

Answer to the body:

First, sculpt the desired join - left or right - as you need.

Then an inner join for your desired property. In this case, by .Owner we group (the same objects as you write).

For example:

 List<T> join = new List<T>(); innerJoin.AddRange(list1); innerJoin.AddRange(list2); var innerJoin = join.GroupBy(pet => pet.id).ToList(); 

You will get grouped items by the parameter by which it is possible to determine that they are the same objects. Understand yourself as better starting from the code you wrote :)

These will be mismatched elements.

And then you decide which one is newer. You know how. (for example, if there is a change date parameter - by it. And you do what you need there)