Combining foreach and using

Posted by apoorv020 on Stack Overflow See other posts from Stack Overflow or by apoorv020
Published on 2010-06-09T11:17:23Z Indexed on 2010/06/09 11:22 UTC
Read the original article Hit count: 178

Filed under:
|
|

I'm iterating over a ManageObjectCollection.( which is part of WMI interface).

However the important thing is, the following line of code. :

foreach (ManagementObject result in results)
{
    //code here
}

The point is that ManageObject also implements IDisposable, so I would like to put "result" variable in a using block. Any idea on how to do this, without getting too weird or complex?

© Stack Overflow or respective owner

Related posts about c#

Related posts about foreach