为什么我不能将这个类转换为接口?

时间:2015-03-08 16:28:52

标签: c# inheritance interface

我有一个通用界面:

public interface IAaa<T> where T : ParentClass {
List<T> MyList {get;}
}

我有一个儿童班&#39; ChildClass&#39;继承自&#39; ParentClass&#39;并实现上面的接口:

public class ChildClass : ParentClass, IAaa<AnotherChildClassThatInheritsFromParentClass>.

在另一个课程中,我正在尝试演员(为上下文编辑):

ParentClass pClass = (ParentClass) new ChildClass();
IAaa<ParentClass> iaaa = (IAaa<ParentClass>) pClass;

但是上面给了我一个&#34;不能从源到目标类型&#34;运行时出错。 我怀疑这是因为ParentClass没有实现IAaa接口。我对么?如果没有,我做错了什么?

谢谢。

0 个答案:

没有答案