开发者

Question regarding generics and inheritance

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<>))
开发者_StackOverflow社区

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, e.g.

Something<>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜