updating ArrayList

  • Thread starter Thread starter Cobus
  • Start date Start date
C

Cobus

Hi Rustam

Why not cast the element inside your arraylist to the struct, modify the
member, and then put it back?
 
Hi.
I have ArrayList that contains structures...
I need to iterate through all structures in this array and update one of
members in this structures...
The first thing that comes to mind is just use foreach, store struct in
temp variable , update it , then write it back to array to the same
position.
Is there more efficient way?

Thanks..
 
Hi,

I think you have select the wrong object to store your data..

Structures are value type and Collections (ArrayList) are more effecient
with reference type since reference type are created as objects mean you
avoid object boxing.

but if the arraylist consist of so many element by bet is to store them in a
static Array (at the initial stage if you can) or
use ToArray method to get a strucure type array from the array list and do
the operation using a for loop

else if the arraylist contain small amout of data, it is to your wish

Nirosh.
 
Back
Top