Search code examples
c#.netlistdata-structuressymmetric-difference

Finding symmetric difference of two lists of objects


Consider two lists (or other appropriate data structures) of the objects of type:

class Object
{
    public string clause;

    public string preamble;
    public string description;
}

I need to build a list of these objects that are NOT perfect matches (preamble and description exactly the same in both). For example, if there is a record in list A whose preamble matches that of one in list B, but their description do not match, it should be included. If their description match, they should not be included (that would be part of their intersection).

I have been going round in circles trying to find a solution, including implementing nested foreach loops. Is there a symmetric difference function for List, or any other appropriate data structure, that can compare objects by comparing their members like this?

For context, one of the lists represents records from an Excel spreadsheet obtained with Epplus library, and the other list represents issues from Jira API.


Solution

  • There is no convenient built-in solution for that, probably because object in .NET is not data. However, there are some projects useful for your problem, like Compare .NET Objects, which can compare object by using reflection and can be configured to list all differences between two objects.