我要制作一种 GetAllContacts 方法, 使用Func( 联系人) 类型参数的排序参数, 与 IEO numberable( 联系人) 的排序方法相同。 这里的代码 :
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
当我调用 GetAllContacts( Func( c) c. ContactID, Sort Directction. Asscating) 时,我就会发现错误 :
"Value of type System.Func(Of Contact, String) cannot be converted to Integer ." on the first parameter
和
"Too many arguments to extension method Public Function ElementAtOrDefault(index As Integer) As Contact defined in System.Linq.Enumerable ." on the second parameter.
我错过了什么?