Method that creates array of objects passed to it?

Nov 29 2003 1:58 PM
Hello, This may seem a pathetically simple question to some of you and I'm sure I'm just not seeing the forest for the trees. class xyz { private object[] array; public xyz(object parameter, int size) { array = new object[size]; foreach(int i = 0; i< size; i++) { array[i] = new typeof(parameter)(3,4); .... This is somewhat pseudo code but I guess you see what I mean. The array should be able to hold any type but I need to then fill it with new instances of whatever I pass to that function. This could be simple ints, but may also be classes where I'd have to pass parameters (here 3,4) to the constructor. Am I thinking to complicated? Many thanks, N.

Answers (1)