[英]Question regarding generics and inheritance
I have a class Derived<T>
that is derived from Base<T>
. 我有一个从
Base<T>
Derived<T>
类。 Which of the following assertions are true or false? 以下哪个断言是对还是错?
typeof(Derived<SomeType>).IsSubclassOf(typeof(Base<SomeType>))
typeof(Derived<>) .IsSubclassOf(typeof(Base<SomeType>))
typeof(Derived<SomeType>).IsSubclassOf(typeof(Base<>))
typeof(Derived<>) .IsSubclassOf(typeof(Base<>))
Thanks in advance 提前致谢
In that case, the first one: 在这种情况下,第一个:
typeof(Derived<SomeType>).IsSubclassOf(typeof(Base<SomeType>))
The other's don't compile- you cannot refer to a generic without it's type argument, eg 另一个不编译-如果没有泛型的类型参数,则不能引用泛型,例如
Something<>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.