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 等也相同...
定义为:
- 必须调用 Appointments 并且必须有一个空的构造函数。
- 它必须实现接口
IAppointments
。
界面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();
}
}
但运气不好,我很困惑。请你帮我如何在 Appoinments
或 Appointment
中实现 IEnumerated<IAppointment>
并继承它?我相信我没有用我的 Appointment
和 Appointments
.
正确实施和继承 IAppointment
和 IAppointments
声明约会class为
public class Appointments : List<IAppointment>, IAppointments
并删除
List<IAppointment> list = null;
在您当前的实施中将 list
更改为 this
。
错误:
'Calendar.Appointments' does not implement interface member 'System.Collections.Generic.ICollection.CopyTo(Calendar.IAppointment[], int)'
添加、清除、计数、IsReanOnly、删除、Indexof 等也相同...
定义为:
- 必须调用 Appointments 并且必须有一个空的构造函数。
- 它必须实现接口
IAppointments
。
界面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();
}
}
但运气不好,我很困惑。请你帮我如何在 Appoinments
或 Appointment
中实现 IEnumerated<IAppointment>
并继承它?我相信我没有用我的 Appointment
和 Appointments
.
IAppointment
和 IAppointments
声明约会class为
public class Appointments : List<IAppointment>, IAppointments
并删除
List<IAppointment> list = null;
在您当前的实施中将 list
更改为 this
。