`using` statement with uninitialized variable not possible, nor is finally, so how to properly dispose it?
<p>Suppose I have a class <code>DisposableObject</code> which implements IDisposable. There is a risk it can throw an exception from any constructor and from the DoStuff function. I want to do something like this, so that no matter what happens, the object is disposed properly:</p>

<p>edit: I would like to avoid duplicate code, so a using inside each if/else block is not desirable (the code is a lot more complex than here)</p>

<p>edit2: Yes the try/finally error was wrong, changed it to use of unassigned local variable.</p>

<pre><code>using (DisposableObject worker)
{
    if(/*condition*/)
        worker = new DisposableObject(/*args*/)
    else
        worker = new DisposableObject(/*other args*/)
    worker.DoStuff();
}
</code></pre>

<p>But I can't, because the compiler says I must provide an initializer in the using statement.
I can't use try/finally either:</p>

<pre><code>DisposableObject worker;
try
{
    if(/*condition*/)
        worker = new DisposableObject(/*args*/)
    else
        worker = new DisposableObject(/*other args*/)
    worker.DoStuff();
}
finally
{
    worker.Dispose();
}
</code></pre>

<p>The compiler says use of unassigned local variable 'worker'.</p>

<p>So what can I do? Obviously I can't simply go like this...</p>

<pre><code>DisposableObject worker;
if (/*condition*/)
    worker = new DisposableObject(/*args*/)
else
    worker = new DisposableObject(/*other args*/)
worker.DoStuff();
worker.Dispose();
</code></pre>

<p>Because I can't be sure the Dispose() function is ever reached.</p>
