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列表,其中泛型未知且可以變化。 –