How does one Dispose an object that is set in foreach?

Posted by Greg Ogle on Stack Overflow See other posts from Stack Overflow or by Greg Ogle
Published on 2010-04-19T20:33:15Z Indexed on 2010/04/19 20:43 UTC
Read the original article Hit count: 190

Filed under:
|
foreach(var someDisposableObject in listOfDisposableObjects)
{
    //some code
    someDisposableObject.Dispose(); //current code contains something like this.
}

Is there safe way, like a using clause to use in this scenario?

© Stack Overflow or respective owner

Related posts about best-practice

Related posts about idisposable