请看下面的代码:
Public Class Student
Public Sub PassList(ByVal StudentList As List(Of Student))
Dim s1 As New Student
Dim s2 As New Student
Dim s3 As New Student
StudentList.Add(s1)
StudentList.Add(s2)
StudentList.Add(s3)
End Sub
Public Sub TestReturnList()
Dim list As List(Of PostGraduate)
PassList(list)
End Sub
End Class
Public Class PostGraduate
Inherits Student
End Class
Public Class PostUndergraduate
Inherits Student
End Class
有一个编译器错误:
'System.Collections.Generic.List(Of WindowsApplication1.PostGraduate)' 类型的值无法转换为 'System.Collections.Generic.List(Of WindowsApplication1.Student)
我理解错误的原因。有解决方法吗?