title: Find duplicates within multiple lists using linq
body: <p>I've got 4 classes each inheriting from the same base class. They all have an Id &amp; Path property in common. When my data is loaded from xml, I build 4 lists based on these classes.</p>
  
  <p>I've got the following code which allows me to compare 2 lists:</p>
  
  <pre><code>var list1 = settings.EmailFolders.Select(m =&gt; m.Path).ToList().
  Intersect(settings.LogPaths.Select(m=&gt;m.Path).ToList()).ToList();
  </code></pre>
  
  <p>but I'd like</p>
  
  <ol>
  <li><p>I want to compare the 1st list to the other 3 and find if there are duplicate path.</p></li>
  <li><p>If none are found, I then want to apply the same logic comparing the second list and compare it to the other 2.</p></li>
  <li><p>If none are found, I then want to apply the same logic comparing the third list and compare it to the last one.</p></li>
  </ol>
  
  <p>Please note that I don't want point 1, 2 and 3 in a single process as I'd like to report the relevant error if duplicates are found.</p>
  
  <p>If I re-use the above and add an additional <code>Intersect</code> with an additional list, </p>
  
  <pre><code>var list1 = settings.EmailFolders.Select(m =&gt; m.Path).ToList().
  Intersect(settings.LogPaths.Select(m=&gt;m.Path).ToList()).
  Intersect(settings.SuccessPaths.Select(m=&gt;m.Path).ToList()).
  Intersect(settings.FailurePaths.Select(m=&gt;m.Path).ToList()).List();
  </code></pre>
  
  <p>The above would like applying an <code>and</code> operator between each rather than an <code>or</code> operator which is not what I want. I need to know if any of the Path used in FailurePaths or LogPaths or SuccessPaths are already used in my EmailFolder.Path</p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>I've updated my question with an answer based on @Devuxer suggestion which is the correct answer but instead of working with string array, I'm basing it on list of classes which all contains a <code>Path</code> property.</p>
  
  <pre><code>List&lt;EmailFolder&gt; emailFolders = LoadEmailFolders();
  List&lt;LogPath&gt; logPaths = LoadLogPaths();
  List&lt;SuccessPath&gt; successPaths = LoadSuccessPaths();
  List&lt;FailurePath&gt; failurePaths = LoadFailurePaths();
  
  var pathCollisions = EmailFolders.Select(a=&gt;a.Path)
  .Intersect(LogPaths.Select(b=&gt;b.Path))
  .Select(x =&gt; new { Type = "LogPath", Path = x })
  .Concat(EmailFolders.Select(c=&gt;c.Path)
  .Intersect(SuccessPaths.Select(d=&gt;d.Path))
  .Select(x =&gt; new { Type = "SuccessPath", Path = x }))
  .Concat(EmailFolders.Select(e=&gt;e.Path)
  .Intersect(FailurePaths.Select(f=&gt;f.Path))
  .Select(x =&gt; new { Type = "FailurePath", Path = x })).ToList();
  </code></pre>
  
  <p>Note that in the above example, for simplicity sake, I've just declared my list with a function for each which loading the relevant data but in my case, all the data is deserialized and loaded at once.</p>