title: Efficient way to clone a HashSet<T>?
body: <p>A few days ago, I answered <a href="https://stackoverflow.com/questions/3897568/substract-hashsets-and-return-a-copy">an interesting question</a> on SO about <code>HashSet&lt;T&gt;</code>. A possible solution involved cloning the hashset, and in my answer I suggested to do something like this:</p>
  
  <pre><code>HashSet&lt;int&gt; original = ...
  HashSet&lt;int&gt; clone = new HashSet&lt;int&gt;(original);
  </code></pre>
  
  <p>Although this approach is quite straightforward, I suspect it's very inefficient: the constructor of the new <code>HashSet&lt;T&gt;</code> needs to separately add each item from the original hashset, and <strong>check if it isn't already present</strong>. This is clearly a waste of time: since the source collection is a <code>ISet&lt;T&gt;</code>, it is guaranteed not to contain duplicates. There should be a way to take advantage of that knowledge...</p>
  
  <p>Ideally, <code>HashSet&lt;T&gt;</code> should implement <code>ICloneable</code>, but unfortunately it's not the case. I also checked with Reflector to see if the <code>HashSet&lt;T&gt;</code> constructor did something specific if the source collection was a hashset, but it doesn't. It could probably be done by using reflection on private fields, but that would be an ugly hack...</p>
  
  <p><strong>So, did someone come up with a clever solution to clone a hashset more efficiently ?</strong></p>
  
  <p>(Note that this question is purely theoretical, I don't need to do that in a real program)</p>