title: Implementing custom indexer on a collection
body: <p>I want to make a custom indexer on a collection. Here are my classes:</p>
  
  <p>Business Class:</p>
  
  <pre><code>public class UserCollection : Collection&lt;User&gt;
  {
      public new User this[int index]
      {
          get
          {
              return this.FirstOrDefault(x =&gt; x.UserID == index);
          }
      }
  
  }
  </code></pre>
  
  <p>BL API Method:</p>
  
  <pre><code>public static Collection&lt;User&gt; GetUser()
  {
      return new UserCollection
                 {
                     new User {UserID = 2},
                     new User {UserID = 4}
                 };
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>  Collection&lt;User&gt; users = GetUser();
      User user = users[2];
  
      }
  </code></pre>
  
  <p>User class has few columns like UserID, UserName etc. I want to fetch a user from collection via index and here index will be user id. But the above usage code is not doing it, and it is  considering indexer of parent Collection class. I want my custom indexer to come into play. I can do it by exposing UserCollection as the return type of GetUser method and then the solution will be to use the code like this</p>
  
  <pre><code>UserCollection users = GetUser();
  </code></pre>
  
  <p>But I am thinking to return the most general type from BL method here which is Collection. How can I solve this issue?</p>