title: Modifying list inside foreach loop
body: <p>I have a construction similar to this (but a <em>lot</em> more complicated):</p>
  
  <pre><code>var list = new List&lt;string&gt;();
  
  // .. populate list ..
  
  foreach(var item in list)
  {
      DoFunction(list);
  }
  
  public void DoFunction(List&lt;string&gt; list)
  {
      if(someCondition == true)
      {
          // .. modify list in here ..
      }
  }
  </code></pre>
  
  <p>Now, I understand that its not possible to edit the collection you're foreaching through, but how do you jump out of the loop gracefully if you do have to edit the list (without a <code>try catch</code> statement)? Is there some way to tell if the list has been edited? Can you edit the list and quickly <code>break;</code> before it notices?</p>