Comparing two lists with LINQ, and retrieve the different items
<p>Assume I have the following object <code>foo</code> and its properties listed below:</p>
<pre><code>class foo
public string name
public string property1
public string property2
</code></pre>
<p>Now let's instantiate two lists of <code>foo</code>: <code>List&lt;foo&gt;()</code></p>
<p>The <strong>first list</strong> contains two <code>foo</code> objects:</p>
<pre><code>new foo() = 
{
   name = &quot;name&quot;,
   property1 = &quot;random value&quot;,
   property1 = &quot;random value&quot;
}

new foo() = 
{
   name = &quot;name&quot;,
   property1 = &quot;random value&quot;,
   property1 = &quot;random value&quot;
}
</code></pre>
<p>The <strong>second list</strong> contains one <code>foo</code> object:</p>
<pre><code>new foo() = 
{
   name = &quot;name&quot;,
   property1 = &quot;random value&quot;,
   property1 = &quot;random value&quot;
}
</code></pre>
<p>Is it possible using <strong>LINQ</strong> to compare and return a new <code>List&lt;foo&gt;</code> that contains the differences between these two lists (or any other list for that matter)? <strong>Taking into consideration that item order and <em>any</em> property value that does not match are also considered as a difference.</strong></p>
<p>This was helpful for primitive objects:
<a href="https://stackoverflow.com/questions/23809841/compare-two-lists-item-by-item-using-linq">Compare two lists, item by item, using linq</a> but does not provide a way to return a new list with the differences.</p>
<h2>EDIT</h2>
<p>@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..</p>
<p>@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.</p>