title: Pass Func(Of TElement, TKey) as a function parameter
body: <p>I want to make a GetAllContacts method which takes a sort parameter of type Func(Of Contact, TKey) which is the same type that the OrderBy method for an IEnumerable(Of Contact) takes.  Here's my code:</p>
  
  <pre><code>    Public Function GetAllContacts(Of TKey)(ByVal sort As Func(Of Contact, TKey), ByVal sortDirection As SortDirection) As IEnumerable(Of Contact) Implements IContactRepository.GetAllContacts
          Select Case sortDirection
              Case sortDirection.Ascending
                  Return ContactList.OrderBy(sort)
              Case sortDirection.Descending
                  Return ContactList.OrderByDescending(sort)
          End Select
      End Function
  </code></pre>
  
  <p>When I call the GetAllContacts(Func(c) c.ContactID, SortDirection.Ascending), I get the error:</p>
  
  <pre><code>"Value of type 'System.Func(Of Contact, String)' cannot be converted to 'Integer'." on the first parameter
  </code></pre>
  
  <p>and</p>
  
  <pre><code>"Too many arguments to extension method 'Public Function ElementAtOrDefault(index As Integer) As Contact' defined in 'System.Linq.Enumerable'." on the second parameter.
  </code></pre>
  
  <p>What am I missing?</p>