<p>Is there a difference (performance, overhead) between these two ways of merging data sets?</p>
<pre><code>MyTypedDataSet aDataSet = new MyTypedDataSet();
aDataSet .Merge(anotherDataSet);
aDataSet .Merge(yetAnotherDataSet);
</code></pre>
<p>and</p>
<pre><code>MyTypedDataSet aDataSet = anotherDataSet;
aDataSet .Merge(yetAnotherDataSet);
</code></pre>
<p>Which do you recommend?</p>

[{'answer_id': 56772, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 3, 'selected': False, 'text': '<p>Those two lines do different things.</p>\n\n<p>The first one creates a new set, and then merges a second set into it.</p>\n\n<p>The second one sets the ds reference to point to the second set, so:</p>\n\n<pre><code>MyTypedDataSet ds1 = new MyTypedDataSet();\nds1.Merge(anotherDataSet);\n//ds1 is a copy of anotherDataSet\nds1.Tables.Add("test")\n\n//anotherDataSet does not contain the new table\n\nMyTypedDataSet ds2 = anotherDataSet;\n//ds12 actually points to anotherDataSet\nds2.Tables.Add("test");\n\n//anotherDataSet now contains the new table\n</code></pre>\n\n<hr>\n\n<p>Ok, let\'s assume that what you meant was:</p>\n\n<pre><code>MyClass o1 = new MyClass();\no1.LoadFrom( /* some data */ );\n\n//vs\n\nMyClass o2 = new MyClass( /* some data */ );\n</code></pre>\n\n<p>Then the latter is better, as the former creates an empty object before populating it.</p>\n\n<p>However unless initialising an empty class has a high cost or is repeated a large number of times the difference is not that important.</p>\n'}, {'answer_id': 56775, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': "<p>Your second example does <strong>not</strong> create a new dataset.  It's just a second <em>reference</em> to an existing dataset.</p>\n"}, {'answer_id': 56781, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 2, 'selected': True, 'text': '<p>While Keith is right, I suppose the example was simply badly chosen. Generally, it is better to initialize to the “right” object from the beginning and <em>not</em> construct an intermediate, empty object as in your case. Two reasons:</p>\n\n<ol>\n<li>Performance. This should be obvious: Object creation costs time so creating less objects is better.</li>\n<li><em>Much</em> more important however, it better states your <strong>intent</strong>. You do generally <em>not</em> intend to create stateless/empty objects. Rather, you intend to create objects with some state or content. Do it. No need to create a useless (because empty) temporary.</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/56767', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1360/']