Well i wrote out a example of the problem .
im not sure what the best way to deal with this type of situation is
or if the way i have it now is the best way.
basically the problem is as follows

Class A
is the base class or the class that each of the following classes will have
at least one instance of within it

Class B and C
class B and C always has derives from A or
will have at least one instance of class A within it .
class B,C these have common methods and variables
and the classes are always created thru class M

Class M
this class has a single private list of Objects ?? to hold class B or C.
as a object of class b or c is created , it is added to M's object list
and classes b c have similar variables or methods for M to identify them uniquely

i have the need for this type of functionality particuarly to add different classes
to some sort of generic list that can be indexed fast

though i dont like the idea really of adding a object of B and C
to a list of objects
though i need to do something like that
as i need a single container of objects of variable classes B and C

now my question is as follows what type of generic can i use that is like list
or should i simply try to cast each of these different class objects to the same class
and then try to add them to a list ect... like a list of objects

Create an interface and implement it in classes B and C. This interface should contain all the common methods. In class M create a List<T> of this interface and add the created classes B and C to this list. Since they implement the same interface, you don't care which class you get from the List, the system will handle it for you.

This article has been dead for over six months. Start a new discussion instead.