【发布时间】:2011-06-11 23:38:23
【问题描述】:
interface Base { ... }
class Sub : Base { ... }
class OtherBase<T> where T : Base { ... }
class OtherSub<T> : OtherBase<T> where T : Base { ... }
//...in some class
void Call<T>() where T : OtherBase<Base> { }
//...
Call<OtherSub<Sub>>(); //compile fails...
似乎在使用泛型时,编译器不会在 泛型类型(OtherBase/OtherSub)。为什么会这样?
更新: 还请解释上面和下面的区别(有效)
void Call<T>() where T : Base { }
//...
Call<Sub>();
【问题讨论】: