In the following, I'm passing a disposable object as a parameter in a constructor, then doing a few operations and that's it. The constructor does nothing other than set a local variable instance of DisposableObject.
Am i right in believing the disposable will still get disposed even in the result of an exception in the Whatever() call?
If the code was in a for loop both objects would also go out of scope and get garbage collected as well (I can only have one instance of this IDisposable class in my App Domain).
using (var disposableObject = new DisposableObject()) { var simpleObject= new Simple(disposableObject); simpleObject.Whatever(); }
disposableObjecthas been created.