一般来说,通用方法对我来说是新的。需要一个返回泛型集合的方法,但也需要一个相同泛型类型的集合并接受
Expression<Func<GenericType, DateTime?>>[] Dates
范围。整个以下函数的 T 应该是相同的类型,所以我现在使用的是(简化版):
private static Collection<T> SortCollection<T>(Collection<T> SortList, Expression<Func<T, DateTime>>[] OrderByDateTime)
{
return SortList.OrderBy(OrderByDateTime[0]);
}
但我收到错误:
错误:无法从用法中推断方法“System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumberable, System.Func)”的类型参数。尝试明确指定类型参数。
有没有办法做到这一点?