title: C# - Any clever way to get an int array from an object collection?
body: <p>How can I create an easy helper method to get an int array from a collection of objects?</p>
  
  <p>The idea would be have a method which receive a collection of "User" class:</p>
  
  <pre><code>public class User { 
      public int UserId {get;set;}
      public string UserName {get;set;}
  }
  </code></pre>
  
  <p>And filter this collection to get an int array of unique UserIds. </p>
  
  <pre><code>List&lt;int&gt; repeatedUserIds = (from item in list 
                               select item.UserId).ToList();
  List&lt;int&gt; uniqueUserIds = ((from n in repeatedUserIds 
                               select n).Distinct()).ToList();
  </code></pre>
  
  <p>Is there a way to create a clever method for this purpose?</p>