为了账号安全,请及时绑定邮箱和手机立即绑定

使用父属性调用父方法

使用父属性调用父方法

C#
泛舟湖上清波郎朗 2021-06-03 05:53:47
我想创建一个排序函数。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 关注
  • 102 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信