Option Explicit On Option Strict On Public Class Class1 Dim l As List(Of A) Public Sub New() l = New List(Of B) End Sub End Class Public Class A End Class Public Class B Inherits A End Class<p>
I’ve run into this problem.
I have a list declared of a Generic Type ‘A’
I want to define the list as a Generic Type ‘B’, which is a subclass of ‘A’.
Why can’t this be done, and how can the same effect be achieved?
It’s a matter of variance, which C# doesn’t support for generics. See Rick Byer’s post on the subject.