作为基础继承的C#转换泛型返回null

时间:2018-12-07 05:34:14

标签: c# generics casting

我有一个名为TabularSectionManager的类,并且每个Manager都链接到TabularBusinessObject。

public abstract class TabularSectionManager<T1> : where T1 : TabularBusinessObject
{
    public TabularSectionManager()
    {
    }

    public T1 LinkedTabularBusinessObject { get; set; } 
}

public class PhoneManager : TabularSectionManager<PhoneBo>
{
    public PhoneManager()
    {

    }
}

public class PhoneBo : TabularBusinessObject
{
    public PhoneBo()
    {

    }
}

最后,还有另一个类存储TabularBusinessObjectManager List的集合。

编译器在此抱怨转换:

List<TabularSectionManager<TabularBusinessObject>> TabularSections { get; set; }

TabularSections.Add(new PhoneManager());
  

错误CS1503参数1:无法从“ PhoneManager”转换为   “ TabularSectionManager ”。

您能对此提出建议吗?

谢谢。

0 个答案:

没有答案