title: Compare one value to several possible list matches
body: <p>I'm back to haunt your dreams! I'm working on comparing some values in a complex loop. List 1 is a list of questions/answers, List 2 is also a list of questions/answers. I want to compare List 1 to List 2 and have duplicates removed from List 1 before merging it with List 2. My problem is in the current seed data I have the two items in List 1 match against List 2, but only one is removed instead of both.</p>
  
  <p>I've been at this a couple days and my head is ready to explode, so I hope I can find some help!</p>
  
  <p>Here's code for you:</p>
  
  <pre><code>//Fetching questions/answers which do not have an attempt
  //Get questions, which automatically pull associated answers thanks to the model
  List&lt;QuizQuestions&gt; notTriedQuestions = await db.QuizQuestions.Where(x=&gt;x.QuizID == report.QuizHeader.QuizID).ToListAsync();
  
  //Compare to existing attempt data and remove duplicate questions
  int i = 0;    
  while(i &lt; notTriedQuestions.Count)
      {
  
      var originalAnswersCount = notTriedQuestions.ElementAt(i).QuizAnswers.Count;
  
          int j = 0;
  
          while(j &lt; originalAnswersCount)
          {
              var comparedID = notTriedQuestions.ElementAt(i).QuizAnswers.ElementAt(j).AnswerID;
  
              if (report.QuizHeader.QuizQuestions.Any(item =&gt; item.QuizAnswers.Any(x =&gt; x.AnswerID == comparedID)))
              {
                  notTriedQuestions.RemoveAt(i);
  
                  //Trip while value and cause break out of loop, otherwise you result in a catch
                  j = originalAnswersCount;
              }
              else
              {
                  j++;
              }
  
  
          }
  
          i++;
      }
  
  //Add filtered list to master list
  foreach (var item in notTriedQuestions)
  {
      report.QuizQuestions.Add(item);
  }
  </code></pre>