How can I create a list of a generic type that will be passed as a parameter (VB.Net)
say I have two POCOs I'm using in EF code first
Public class C1
property F1 as integer
End Class
Public class C2
property F2 as String
End Class
I want to have a function that will create a list either of C1 or C2, to be used in some generic operation, such that
Sub MySub(type_of_class)
private lst as new List(of type_of_class)
...
End Sub
Will either create a list of C1 or of C2.
I know generics are probably the an开发者_高级运维swer by my knowlege is kind of generic :-)
thanks!
Generics is your answer, but there is a lot more to it. Your sub should be:
Public Sub MySub(Of T)()
Dim MyT As T
'do stuff with T
End Sub
and called as this
MySub(Of C1)()
For more (starting) info: msdn
Success, Marcel
精彩评论