关于泛型和继承的问题
我有一个派生自 Base
的 Derived
类。以下哪些断言是正确的还是错误的?
typeof(Derived<SomeType>).IsSubclassOf(typeof(Base<SomeType>))
typeof(Derived<>) .IsSubclassOf(typeof(Base<SomeType>))
typeof(Derived<SomeType>).IsSubclassOf(typeof(Base<>))
typeof(Derived<>) .IsSubclassOf(typeof(Base<>))
提前致谢
I have a class Derived<T>
that is derived from Base<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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,第一个:
另一个不能编译 - 你不能在没有类型参数的情况下引用泛型,例如
In that case, the first one:
The other's don't compile- you cannot refer to a generic without it's type argument, e.g.