views:

115

answers:

3
+2  Q: 

Generic Object

I have a class declared as follows:

Public MustInherit Container(Of T As {New, BaseClass}) Inherits ArrayList(Of T)

I have classes that inherit this class.

I have another class that I must pass instances in this method:

Public Sub LoadCollection(Of T As {BaseClass, New})(ByRef Collection As Container(Of T))

I need to store the passed in object in a global variable, but i can't simply declare it:

Private _Container as Collection(Of BaseClass)

What is the syntax to declare this object?

A: 

It cannot be a global variable. Container is an idea, not a thing.

As you have it designed, that idea is only formed into an actual thing inside LoadCollection(). You need to convey the information outside of that method.

James Curran
A: 

Hmmm. "Collection" is a variable name, not a Type. I think this is what you want:

Private _Container as Container(Of BaseClass)

Also, ArrayList is not a Generic class; don't you mean Inherits List(of T) ?

+1  A: 

Sorry haven't got time to expand on this right now, but I think this link describes your underlying problem and a solution.

(You might also find this interesting.)

Ian Horwill