我想创建一个排序函数。public class Program { public static void Main() { // the error is here Child1.SortList(new List<Child1>() {}); }}public class Parent{ public string Code { get; set; } public Nullable<decimal> Order { get; set; } public DateTime DateBegin { get; set; } public Nullable<DateTime> DateEnd { get; set; } public static List<Parent> SortList(List<Parent> list) { return list .Where(x => DateTime.Compare(x.DateBegin, DateTime.Today) <= 0 && ( x.DateEnd == null || DateTime.Compare((DateTime)x.DateEnd, DateTime.Today) > 0)) .OrderBy(x => x.Order) .ToList(); }}public class Child1 : Parent{ public string Description { get; set; }}当我打电话时SortList(),我收到一个错误,无法转换Child1为Parent. 我不知道如何实现接口或T?
1 回答
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消