title: is there a way to set a variable to something at the end of foreach loop if condition not met in C#?
body: <pre><code>foreach (Objecta a in aList())
  {
      foreach (Objectb b in bList)
      {
          if (a.variable != b.variable1 &amp;&amp; a.variable() != b.variable2)
          {
              a.setVariable("Error");
          }
      }
  }
  </code></pre>
  
  <p>The problem I am getting is that it goes through the foreach loop the first time and it sets variable to error without checking if other values (when it goes through the loop again) finds a match.</p>
  
  <p>What I would like is to wait until it goes through all the lists and at the last <code>foreach</code> loop iteration if nothing in <code>aList</code> matches the variable target &amp;&amp; variable source in <code>bList</code> then finally set it to Error flag. </p>
  
  <p>Any suggestions to get around this will be appreciated. </p>