title: For each with a dynamic list?
body: <p>I have a for each loop that runs through the database to check for files that have been flagged for conversion. Currently I have the following code:</p>
  
  <pre><code>            /* All files flagged for invidual conversion will be stored in here. */
              ArrayList files = vc.getFilesForInvidualConversion();
              foreach (FileInfoExtended file in files)
              {
                  // As long as the status flag hasn't been changed it can continue.
                  if (abort == false)
                  {
                      if (vc.isFileInUse(file) == false)
                      {
                              // Converting the video file.
                              vc.convertVideoToFLV(file);
                      }
                  }
                  vc.getFilesForInvidualConversion();
              }
  </code></pre>
  
  <p>In the first line you can see I fill an ArrayList with objects which it will run through with a for each. However, after each file in the list I want to check for possible new files that need to be converted. When I fill the ArrayList again the for each doesn't seem to notice, it keeps working with the original files received from the first line of code. I'd rather want it to update the "files"-ArrayList so that it can convert the new files as well.</p>
  
  <p>Is this possible?</p>
  
  <p><strong>EDIT:</strong> The anwsers you gave all work for this scenario, but I want to add something. Is it possible to remove a file from the list during the loop? And to make it so it won't convert that one?</p>
  
  <p><strong>EDIT 2:</strong> This is what I have now:</p>
  
  <pre><code>            List&lt;FileInfoExtended&gt; files = vc.getFilesForInvidualConversion();
              while (files.Count &gt; 0)
              {
                  if (abort == false)
                  {
                      if (vc.isFileInUse(files[0]))
                      {
                          vc.convertVideoToFLV(files[0]);
                      }
                  }
                  files = vc.getFilesForInvidualConversion();
              }
  </code></pre>
  
  <p>And it works in both cases (when a file is added to the list and when a file is removed from the list). I don't know if it is performance wise a good solution, but right now it suits my needs. Unless there are some issues I'm overlooking?</p>
  
  <p>Any comment will be appreciated!
  Kind regards,
  Floris</p>