title: Select an element by index from a .NET HashSet
body: <p>At the moment I am using a custom class derived from <code>HashSet</code>.  There's a point in the code when I select items under certain condition:</p>
  
  <pre><code>var c = clusters.Where(x => x.Label != null && x.Label.Equals(someLabel));</code></pre>
  
  <p>It works fine and I get those elements. But is there a way that I could receive an index of that element within the collection to use with <code>ElementAt</code> method, instead of whole objects?</p>
  
  <p>It would look more or less like this:</p>
  
  <pre><code>var c = select element index in collection under certain condition;
  int index = c.ElementAt(0); //get first index
  clusters.ElementAt(index).RunObjectMthod();</code></pre>
  
  <p>Is manually iterating over the whole collection a better way?  I need to add that it's in a bigger loop, so this <code>Where</code> clause is performed multiple times for different <code>someLabel</code> strings.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>What I need this for? <code>clusters</code> is a set of clusters of some documents collection. Documents are grouped into clusters by topics similarity. So one of the last step of the algorithm is to discover label for each cluster. But algorithm is not perfect and sometimes it makes two or more clusters with the same label. What I want to do is simply merge those cluster into big one.</p>