相关疑难解决方法(0)

为什么泛型类型约束会导致无隐式引用转换错误?

我创建了几个用于处理议程约会的接口和泛型类:

interface IAppointment<T> where T : IAppointmentProperties
{
    T Properties { get; set; }
}

interface IAppointmentEntry<T> where T : IAppointment<IAppointmentProperties>
{
    DateTime Date { get; set; }
    T Appointment { get; set; }
}

interface IAppointmentProperties 
{
    string Description { get; set; }
}

class Appointment<T> : IAppointment<T> where T : IAppointmentProperties
{
    public T Properties { get; set; }
}

class AppointmentEntry<T> : IAppointmentEntry<T> where T : IAppointment<IAppointmentProperties>
{
    public DateTime Date { get; set; }
    public T …
Run Code Online (Sandbox Code Playgroud)

c# generics type-constraints implicit-conversion

41
推荐指数
3
解决办法
4万
查看次数