1
请参阅我的下面的代码,我试图创建一个使用泛型的接口列表,但我需要泛型版本。因此,您知道,泛型类型可能会因列表中的每个条目而有所不同,它不仅仅是具有相同泛型类型的IFoo列表。如何创建泛型列表?
如果您需要澄清,请让我知道。
Public Interface IFoo
End Interface
Public Interface IFoo(Of T)
Inherits IFoo
Function Bar(foo As T) As T
End Interface
Public Class Foo(Of T)
Implements IFoo(Of T)
Private ReadOnly Foos As List(Of IFoo)
Public Function Bar(foo As T) As T Implements IFoo(Of T).Bar
For Each i In Foos
' Can't call Bar function from IFoo(Of T) as IFoo does not define the Bar function.
Next
End Function
End Class
您确定要在Bar函数内调用Bar函数?! – Grim
@Grim可能不是最好的例子,但是,它与我的实际场景很相似。我的问题是关于如何创建一个IFoo列表,其中泛型未知且可以变化。 –