Possible Duplicate:
Why isn’t there generic variance for classes in C# 4.0?
As a rookie programmer I have a couple of questions about variance in .NET 4. Not so much about how it works, but why certain things are not variant and if other people would find this useful.
Question 1:
I know that interfaces and delegates can be covariant/contravariant in .NET 4, but why not classes? So, question 1:
List(of BaseClass) = List(of DerivedClass)
Is this somehow unsafe? Wouldn't this be useful?
Question 2:
Question 2 follows from question 1, but may deal more with signatures than variance. Suppose I have a MustInherit class with a MustOverride member:
Public MustInherit Class TestBase
Public MustOverride Property SomeClass as BaseClass
End Class
In the derived class, why can't I override SomeClass and return a Derived Class Of BaseClass? Is this unsafe? Is it just that the signatures don't check for inheritance relationships?
Public Class TestSpecific
Inherits TestBase
Public Overrides Property SomeClass as DerivedClass
End Class
Any insight as to why this isn't allowed in .NET 4 would be appreciated.