Assume I have the following object foo
and its properties listed below:
class foo
public string name
public string property1
public string property2
Now let's instantiate two lists of foo
: List<foo>()
The first list contains two foo
objects:
new foo() =
{
name = "name",
property1 = "random value",
property1 = "random value"
}
new foo() =
{
name = "name",
property1 = "random value",
property1 = "random value"
}
The second list contains one foo
object:
new foo() =
{
name = "name",
property1 = "random value",
property1 = "random value"
}
Is it possible using LINQ to compare and return a new List<foo>
that contains the differences between these two lists (or any other list for that matter)? Taking into consideration that item order and any property value that does not match are also considered as a difference.
This was helpful for primitive objects: Compare two lists, item by item, using linq but does not provide a way to return a new list with the differences.
EDIT
@CSharpie reopened... Also now the question looks very poorly defined - i.e. what is expected result for {1,2,3,4} and {1,3,4}? Possibly OP is looking for some sort of diff..
@AlexeiLevenkov The output should be 2. Or for a list of {1,2,3,4} and {1,3,2, 4} the output should be {3,2} since the order (or values) of 3 and 2 have changed from the original list.