title: C# Compare two list of same object type
body: <p>I am trying to compare two list of same type using multiple properties of that type.</p>
  
  <p>For example,</p>
  
  <p>I have a class named Details</p>
  
  <pre><code>public class Details
  {
      public   int id;
      public string symbol;
      public string code;
  }
  </code></pre>
  
  <p>I have below two lists:</p>
  
  <pre><code>List&lt;Details&gt; list1 = new List&lt;Details&gt;();  
  List&lt;Details&gt; list2 = new List&lt;Details&gt;();
  
  list1.Add(new Details() { id=1,symbol="ANSI",code="NITE"});
  list1.Add(new Details() { id = 1, symbol = "ANSI", code = "CALGO" });
  list1.Add(new Details() { id = 1, symbol = "ANSI", code = "CANT" });
  list1.Add(new Details() { id=2,symbol="ANSI",code="NITE"});
  list1.Add(new Details() { id = 2, symbol = "ANSI", code = "CALGO" });
  list1.Add(new Details() { id = 2, symbol = "ANSI", code = "CANT" });
  
  list2.Add(new Details() { id = 1, symbol = "ANSI", code = "NITE" });
  list2.Add(new Details() { id = 1, symbol = "ANSI", code = "CALGO" });
  list2.Add(new Details() { id = 2, symbol = "ANSI", code = "NITE" });
  </code></pre>
  
  <p>I want only that data from List1 which has same id, symbol but different code.</p>
  
  <p>So, in above scenario result will be as below.</p>
  
  <pre><code>list1.Add(new Details() { id = 1, symbol = "ANSI", code = "CANT" });
  list1.Add(new Details() { id = 2, symbol = "ANSI", code = "CALGO" });
  list1.Add(new Details() { id = 2, symbol = "ANSI", code = "CANT" });
  </code></pre>
  
  <p>It would be great if this can be achieved through Linq instead of using foreach.</p>
  
  <p>I tried below but that's not correct.</p>
  
  <pre><code>var temp =list1.Where(x=&gt;list2.Any(z=&gt;x.id==z.id &amp;&amp; string.Equals(x.symbol,z.symbol) &amp;&amp; !string.Equals(x.code,z.code)));
  </code></pre>