Best way to obtain a dynamic array of Int

  • Thread starter Thread starter azerty
  • Start date Start date
A

azerty

Hello

I need obtain an int[] tab in my application, It is very important that the
performance would be "perfect" and I can not know the size of it before the
process to obtains different int values ...

now, I do like this :

ArrayList al = new ArrayList();
while (myCondition())
{
.....
al.Add(myInt);
}
return (int[])al.ToArray(typeof(int));


but may be you have better way to do this ?

thanks a lot for your help !!
 
thanks for your answer !

but with this technic, I must do
while (myCondition())
{
....
}

Two times !

First time to know then "count value"

and second time to populate the Int[] tab values !!!

:-)
 
After some tests

I found a better way to create my int[] instance.

in fact, I reproduce the same algo of ArrayList (see with Reflector utility)
but without boxing/unboxing (I manipulate directly int[] and not object[])


int count = 0;

while (myCondition())
{
count ++;
}

return new int[count];


Cheers

Chris
 
Back
Top