How to avoid creating unneeded object in an elegant way?
<p>The root of my question is that the C# compiler is too smart. It detects a path via which an object could be undefined, so demands that I fill it. In the code, I look at the tables in a DataSet to see if there is one that I want. If not, I create a new one. I know that dtOut will always be assigned a value, but the the compiler is not happy unless it's assigned a value when declared. This is inelegant.</p>

<p>How do I rewrite this in a more elegant way? </p>

<pre><code>             System.Data.DataTable dtOut = new System.Data.DataTable();
            .
            .
            // find table with tablename = grp
            // if none, create new table
            bool bTableFound = false;
            foreach (System.Data.DataTable d1 in dsOut.Tables)
            {
                string d1_name = d1.TableName;
                if (d1_name.Equals(grp))
                {
                    dtOut = d1;
                    bTableFound = true;
                    break;
                }
            }

            if (!bTableFound) dtOut = RptTable(grp);
</code></pre>
