title: How to properly update a datatable while inside a loop
body: <p>In my below code I'm comparing values (email addresses) in my Arrarylist (called emails) with values in my Datatable (called dtResult).  I was hoping to be able to remove rows from the datatable if it has an email address that is found in the arraylist but I'm starting to think I'm better off creating a new datatable that does not have those rows instead (I just don't know how to do that).  Obviously my code below bombs after a row is deleted because it loses its place in the foreach loop.  How can I fix this?</p>
  
  <p>Thanks.</p>
  
  <pre><code>foreach (DataRow row in dtResult.Rows)
  {
    var tmpl = row[3];
    for (int x = 0; x &lt; emails.Count; x++)  //emails is an ArrayList of email addresses
    {
      string one = emails[x].ToString().ToUpper();
      string two = tmpl.ToString().ToUpper();
      //compare datatable value to arraylist value..
      if (one == two)
      {
        //if they are equal then I want to remove them (or maybe create a new datatable??)
        dtResult.Rows.Remove(row);
        dtResult.AcceptChanges();
      }
    }
  }
  </code></pre>