title: HashSet or Distinct to read distinct values of property in List<> of objects
body: <p>This is in someway related to this (<a href="https://stackoverflow.com/questions/1388361/getting-all-unique-items-in-a-c-sharp-list">Getting all unique Items in a C# list</a>) question.</p>
  
  <p>The above question is talking about a simple array of values though. I have an object returned from a third party web service:</p>
  
  <pre><code>public class X
  {
      public Enum y {get; set;}
  
  }
  </code></pre>
  
  <p>I have a List of these objects <code>List&lt;x&gt; data;</code>, about 100 records in total but variable. Now I want all the possible values in the list of the property <code>y</code> and I want to bind this do a <code>CheckBoxList.DataSource</code> (in case that makes a difference). </p>
  
  <p>Hows the most efficient way to do this? </p>
  
  <p>I can think of two algorithms:</p>
  
  <pre><code>var data = HashSet&lt;Enum&gt; hashSet = new HashSet&lt;Enum&gt;(xs.Select(s =&gt; s.y));
  chkBoxList.DataSource = data;
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>var data = xs.Select(s =&gt; s.y).Distinct();
  chkBoxList.DataSource = data;
  </code></pre>
  
  <p>My gut feeling is the HashSet but I'm not 100% sure.</p>
  
  <p>Open to better ideas if anyone has any idea?</p>