title: Does HashSet preserve insertion order?
body: <p>Does the <a href="https://msdn.microsoft.com/en-us/library/bb359438(v=vs.110).aspx" rel="noreferrer"><code>HashSet</code></a> collection introduced in .NET 3.5 preserve insertion order when iterated using <code>foreach</code>? </p>
  
  <p>The <a href="http://msdn.microsoft.com/en-us/library/bb397727.aspx" rel="noreferrer">documentation</a> states, that the collection is not sorted, but it doesn't say anything about insertion order. A pre-release BCL <a href="http://blogs.msdn.com/bclteam/archive/2006/11/09/introducing-hashset-t-kim-hamilton.aspx" rel="noreferrer">blog entry</a> states that it is unordered, but <a href="http://www.vcskicks.com/hashset.php" rel="noreferrer">this article</a> states that it is designed to preserve insertion order. My limited testing suggests, that order is preserved, but that could be a coincidence.</p>