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<>
精彩评论