Comparing two lists for duplicates in either of them in C#
<p>I have two Lists like so:</p>

<pre><code>List&lt;EmpData&gt; colExistingEmpData;
List&lt;EmpData&gt; colExternalEmpData;
</code></pre>

<p>Each of them will have employee records that have the same Id.
I know this sounds wierd but that's a real situation I am in right now!</p>

<p>For every employee in colExternalEmpData based on EmpId a check is made on colExistingEmpData</p>

<pre><code>foreach (EmpData employee in colExternalEmpData)
{
  var queryResult = colExistingEmpData.FindAll(thisEmployee =&gt; thisEmployee.Id == employee.Id);

  if(querResult.count == 0)
  {
    // Mark as INSERT
  } 
  else if(querResult.count == 1)
  {
    // Mark as UPDATE
  }
  else // queryResult is more than 1
  {
    // data is duplicated mark as IGNORE
  }

  analysedData.Add(employee);
</code></pre>

<p>This works fine when colExistingEmpData has no duplicated value for the 'Id'</p>

<p>When there are duplicates in colExternalEmpData, meaning if two employees have same 'ID' as 123 the above code will still mark the existing employee with 123 id as update because it finds an exact match in colExistingEmpData provided colExistingEmpData has just one reocrd with that Id.</p>

<p>Is there a way in which an employee record can be marked as 'IGNORE' when it's repeated in either of the sources?</p>

<p>I can't use a Dictionary object, I had used it before but the powers that be didn't like the idea.</p>

<p>Regards.</p>
