Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><ol> <li><p>A <code>HashSet</code> holds a set of objects, but in a way that it allows you to easily and quickly determine whether an object is already in the set or not. It does so by internally managing an array and storing the object using an index which is calculated from the hashcode of the object. <a href="http://www.esus.com/docs/GetQuestionPage.jsp?uid=804">Take a look here</a></p></li> <li><p><code>HashSet</code> is an unordered collection containing unique elements. It has the standard collection operations Add, Remove, Contains, but since it uses a hash-based implementation, these operations are O(1). (As opposed to List for example, which is O(n) for Contains and Remove.) <code>HashSet</code> also provides standard set operations such as <em>union</em>, <em>intersection</em>, and <em>symmetric difference</em>.<a href="http://blogs.msdn.com/b/bclteam/archive/2006/11/09/introducing-hashset-t-kim-hamilton.aspx">Take a look here</a></p></li> </ol></li> <li><p>There are different implementations of Sets. Some make insertion and lookup operations super fast by hashing elements. However, that means that the order in which the elements were added is lost. Other implementations preserve the added order at the cost of slower running times.</p></li> </ol> <p>The <code>HashSet</code> class in C# goes for the first approach, thus <strong>not</strong> preserving the order of elements. It is much faster than a regular <code>List</code>. Some basic benchmarks showed that HashSet is decently faster when dealing with primary types (int, double, bool, etc.). It is a lot faster when working with class objects. So that point is that HashSet is fast.</p> <p>The only catch of <code>HashSet</code> is that there is no access by indices. To access elements you can either use an enumerator or use the built-in function to convert the <code>HashSet</code> into a <code>List</code> and iterate through that.<a href="http://ezinearticles.com/?C-HashSet-Advantages&amp;id=1761474">Take a look here</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload