对于这个问题我有这些类:VB泛型“不能转换”
Public MustInherit Class BaseLeaf(Of T)
Implements IBaseLeaf
// etc
Public Class WebsiteLeaf
Inherits BaseLeaf(Of Headline)
// etc
Public Class WebsiteCollection
Inherits BaseCollection(Of WebsiteLeaf)
// etc
Public Class SubscriptionList
Private mCollection As BaseCollection(Of IBaseLeaf)
Public Sub LoadSubscriptions(ByVal collection As BaseCollection(Of IBaseLeaf))
mCollection = collection
End Sub
在主类我想调用下面的函数:
Private Sub FetchSubscriptions(ByVal websites As WebsiteCollection)
gUser.SubscriptionList.LoadSubscriptions(websites)
// code
End Sub
这将访问LoadSubscriptions与传递“网站”变量。
正如你所看到的LoadSubscriptions需要一个BaseCollection(IBaseLeaf)。
“网站”变量是一个WebsiteCollection,它是BaseCollection(Of WebsiteLeaf(标题))。
现在我收到错误:类型'WebsiteCollection'的值无法转换为'BaseCollection(Of IBaseLeaf)'。
我在做什么错在这里?
您可能想了解[泛型中的协变和逆变](http://msdn.microsoft.com/zh-cn/library/dd799517.aspx) – MarkJ 2012-03-08 20:21:33