tags:

views:

134

answers:

1

Hi,

Is there anyway to have a typed array where each element is a different object?

+2  A: 

Yep, you could have all the generic type be some super class or interface all of all of your objects share.

Like you might have Apple and Orange inherit from Fruit so you could put them both in a List<Fruit>.

Alternatively, if the objects are all of totally different types you could make a List<object>, but that would undermine the value of generics quite a bit. (For Harvey) Such as fewer casts, better intelliprompt, linq, and better performance if you are using collections of structs such as ints and doubles.

Jake Pearson