Is the following a safe way of iterating through disposable objects? Or will this result in indisposed objects? etc? What if I used dispose statements instead of the using nests?
public static void Main()
{
foreach (ChildObject oChild in webApp)
{
//On Noes! Unexpected Error!
}
}
public static IEnumerable<ChildObject> SafelyGetNextObjInWebApp(WebApplication webApp)
{
foreach (ParentObject oParent in webApp.Parents)
{
using (parent)
{
foreach (ChildObject oChild in oParent.Children)
{
using (oChild)
{
yield return oChild;
}
}
}
}
}