title: How to compare, in C#, two lists of objects on one or more properties of these objects?
body: <p>First of all I must say I'm not a seasoned programmer. I looked at similar problems on StackOverflow but didn't seem to find a suitable answer that I can implement with my limited skills.</p>
  
  <p>In C#, I need to compare two lists of objects based on the values of one or more properties in those objects. I want to create two new lists, one of the objects that exist in the left, but have differences in some property values in, or don't exist at all in the right list and vice versa.</p>
  
  <p>Before I only had to compare the two based on one value, so I did not have to work on objects but on string, so I did something like this:</p>
  
  <pre><code>(LeftItems and RightItems are Entities)
  
  List&lt;String&gt; leftList = new List&lt;string&gt;();
  List&lt;String&gt; rightList = new List&lt;string&gt;();
  List&lt;String&gt; leftResultList = new List&lt;string&gt;();
  List&lt;String&gt; rightResultList = new List&lt;string&gt;();
  List&lt;String&gt; leftResultObjList = new List&lt;string&gt;();
  List&lt;String&gt; rightResultObjList = new List&lt;string&gt;();
  
  
  foreach (item i in leftItems)
  {
    leftlist.Add(i.value);
  }
  
  //same for right 
  
  foreach (string i in leftList)
  {
    if(!rightList.contains(i))
    {
      leftResultList.Add(i);
    }
  }
  
  //same for the right list
  </code></pre>
  
  <p>Now I have to compare on more than one value, so I created a class which has several properties that I need to compare, so I'd like to do the same as the above, but with object properties:</p>
  
  <pre><code>class CompItems
  {
    string _x;
    string _y;
  
    public CompItems(string x, string y)
          {
           _x = x;
           _y = y;
          }
  }
  
  foreach (item i in leftItems)
  {
    leftList.Add(new CompItem(i.value1,i.value2));
  }
  
  //same for the right list
  
  foreach (CompItem c in leftItems)
  {
    // Here is where things go wrong
    if(one property of object in rightItems equals property of object in leftItems) &amp;&amp; some other comparisons
    {
      resultLeftObjList.Add(c)
    }
  }
  
  //And the same for the right list
  </code></pre>