Integers in ArrayList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jesper

    Integers in ArrayList

    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.
  • Jon Skeet

    #2
    Re: Integers in ArrayList

    Jesper <jeodni@hotmail .com> wrote:[color=blue]
    > 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?[/color]

    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 :)

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...