Integers in ArrayList

  • Thread starter Thread starter Jesper
  • Start date Start date
J

Jesper

Hi,

How, I would like to make a collection of integers. As an
integer is not a class I can't figure out how to store it
in a collection. The list will be generated dynamically.
Any suggestions.

int i = new int()
i = 5;
arrayList.Add(i) ... Seems to compile, but is this a
reccomended way to do it?

best regards Jesper.
 
Jesper said:
How, I would like to make a collection of integers. As an
integer is not a class I can't figure out how to store it
in a collection. The list will be generated dynamically.
Any suggestions.

int i = new int()
i = 5;
arrayList.Add(i) ... Seems to compile, but is this a
reccomended way to do it?

The above will work, but will take much more memory, because each value
is boxed. Unless you write your own version of ArrayList which stores
the values as an int[] however, you're not going to do much better. I
seem to remember that someone may have a tool somewhere to generate
collections like that automatically, but I don't have a URL for you.

I can't remember offhand whether the generics in the next version of
..NET will fix this problem or not, but it'd be nice if they did :)
 
Back
Top