I recently got access to a very old C# code base (very old meaning .NET 1.1 and C# 1.2) in order to find places that could be improved. It is like a window to the past when a bow was the most powerfull weapon. I have never had the opportunity to willingly code in C# version lesser than C# 2 before.
Basically, what I have found is that there is a whole bunch of large ArrayList
s for storing numbers and structs. By large I mean tens or hundreds of thousand of values. Something like
ArrayList numbers = new ArrayList();
for(int i = 0; i < BIG_CONSTANT; i++)
numbers.Add(someNumberReturnedFromMethod);
These lists are sorted on some place then again sorted by a different standard on another place, or there are searches performed on them.
Knowing that ArrayList
works with objects results in two problems I came up with
- no type-safety
- boxing and unboxing everywhere
So the question is, how to solve this without the aid of generics? I definitely will not make classes from these structs in order to remove un/boxing, because with so many data, this really makes difference (tested).
I thought about creating custom array lists that would work with my structs instead. Do I have to create a custom array list implementation for every struct there is? Thinging about it, it would mean to define my own IEnumerable, ICollection and IList for each of these structs, right?
I think that it could be a good cost to pay in order to get more performing and type-safe system, but before trying it out I would like to know your opinion.