Generic Indexer - speed & safety issues

Nov 27 2003 10:01 AM
Hello, I'm currently working on a simple genetic algorithm where I have implemented the chromosomes as a class working as an indexer. The class holds a private array of type object representing the genes. I've done that to keep flexible with regards to using different representations (int, float, bits etc.). Now, because of that, the genes can be assigned different types (e.g. Genes 1-3 = int, Genes 4 - 5 = strings.) This is nice, but not desirable (accidental assignments of the wrong type may happen). I also suspect that this flexibility costs speed as the program has to juggle around the different types as and when they are assigned to the individual genes. Is this the case, and is there a reason for concern? Would I be better of defining a template (does that work in c#?) or just setting up a class with lots of overloaded methods (for the individual types)? Many thanks, N.

Answers (2)