IEnumerable<IAppointment> 在 class Appointments.cs 处导致 11 个错误

IEnumerable<IAppointment> is causing 11 errors at class Appointments.cs

错误:

'Calendar.Appointments' does not implement interface member 'System.Collections.Generic.ICollection.CopyTo(Calendar.IAppointment[], int)'

添加、清除、计数、IsReanOnly、删除、Indexof 等也相同...

定义为:

界面IAppointments如下:

public interface IAppointments : IList<IAppointment> 
{ 
    bool Load();
    bool Save();
    IEnumerable<IAppointment> GetAppointmentsOnDate(DateTime date);
}

界面IAppointment如下:

public interface IAppointment 
{ 
   DateTime Start { get; }
   int Length { get; }
   string DisplayableDescription { get; }
   bool OccursOnDate(DateTime date); 
}

因为实现IAppointments的class也必须实现IList<IAppointment>(从上面接口的定义),你可能会考虑实现Appointments class 作为实现 IList<IAppointment> 的 class 的子 class - 例如 List<IAppointment>.

我写道:

 public class Appointments : IAppointments
 {
    List<IAppointment> list = null;

    public bool Load() 
    {
        bool flag = false;
        GetEnumerableList(list);
        return flag;
    }

    public bool Save() 
    {
        bool flag = false;

        return flag;
    }

    public IEnumerable<IAppointment> GetAppointmentsOnDate(DateTime day) 
    {
        List<IAppointment> day_list = new List<IAppointment>();

        foreach (var item in list)
        {
            if (item.Start == day) day_list.Add(item);
        }

        return day_list;
    }

    public List<IAppointment>    
    GetEnumerableList(IEnumerable<IAppointment> Enumerable)
    {
        foreach (var item in Enumerable)
        {
            list.Add(item);
        }
        return list;
    }

  public class Appointment : IEnumerable<IAppointment>, IAppointment
  {
      public DateTime Start { get; set; }
      public int Length { get; set; }
      public string DisplayableDescription { get; set; }

      public bool OccursOnDate(DateTime date)
      {
        return false;
      }

      IEnumerator<IAppointment> IEnumerable<IAppointment>.GetEnumerator()
      {
          throw new NotImplementedException();
      }

      System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
      {
          throw new NotImplementedException();
      }
  }

但运气不好,我很困惑。请你帮我如何在 AppoinmentsAppointment 中实现 IEnumerated<IAppointment> 并继承它?我相信我没有用我的 AppointmentAppointments.

正确实施和继承 IAppointmentIAppointments

声明约会class为

public class Appointments : List<IAppointment>, IAppointments

并删除

List<IAppointment> list = null;

在您当前的实施中将 list 更改为 this