updating ArrayList

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

    #1

    updating ArrayList

    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..

  • Cobus

    #2
    Re: updating ArrayList

    Hi Rustam

    Why not cast the element inside your arraylist to the struct, modify the
    member, and then put it back?

    --
    Cobus Lombard
    Application Developer
    Mint Net
    South Africa

    "Rustam Asgarov" <rustam@boun.ed u.tr> wrote in message
    news:%238AUGEOt DHA.2148@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > 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..
    >[/color]


    Comment

    • Champika Nirosh

      #3
      Re: updating ArrayList

      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.

      "Rustam Asgarov" <rustam@boun.ed u.tr> wrote in message
      news:#8AUGEOtDH A.2148@TK2MSFTN GP12.phx.gbl...[color=blue]
      > 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..
      >[/color]


      Comment

      Working...