0
Answer

Generics

Pete Burkindine

Pete Burkindine

14y
1.5k
1

Hi, all,

I have a class("Parent") that keeps a dictionary of items of another class("Child").  I am trying to make Child generic.  This is in a base dll, with different implementations using the generic Child differently.
Please forgive the psuedocode...

I don't want to make Parent generic (this would mean making about a dozen other classes generic besides), but it needs to know the type to pass to the dictionary constructor:

Dictionary _d = New Dictionary(Of string, Child(of ____))

I could just use object, but that would defeat the purpose.

I was hoping something like:

Type _childType = (typeof constructorParam)

and then...

Dictionary _d = New Dictionary(Of string, Child(of _childType))

...would work. Instead, the compiler says 'Type _childType' is not defined.

I am hoping there is an easy way to do this.  Thanks!

Next Recommended Forum