title: How does one Dispose an object that is set in foreach?
body: <pre><code>foreach(var someDisposableObject in listOfDisposableObjects)
  {
      //some code
      someDisposableObject.Dispose(); //current code contains something like this.
  }
  </code></pre>
  
  <p>Is there safe way, like a <code>using</code> clause to use in this scenario?</p>
  
  <p>For my second iteration (before getting responses) I changed the code to </p>
  
  <pre><code>foreach(var someDisposableObject in listOfDisposableObjects)
  {
      try
      {
          //some code
      }
      finally
      {
          someDisposableObject.Dispose(); //current code contains something like this.
      }
  }
  </code></pre>
  
  <p>though </p>
  
  <pre><code>foreach(var someDisposableObject in listOfDisposableObjects)
  {
      using( someDisposableObject )
      {
          //some code
      }
  }
  </code></pre>
  
  <p>is much more tidy and most likely safer.</p>